Ajax-PHP无法正常工作

AJAX-PHP错误再次让我感到困惑。现在问题出在这里
我将使用AJAX将一些表单数据从HTML发送到PHP,(我正在使用jQuery),然后使用该数据,在PHP中使用它并给出一些结果。
Ajax调用成功完成,但问题是并非所有数据都被发送到PHP, if I interpreted it correctly会丢失一些数据
jQuery / Ajax代码

 $(document).ready(function(){ $("#button").click(function(e){ e.preventDefault(); var data=$("#Form").serialize(); console.log(data); $.ajax({ type:'POST', url:('php/api.php'), data:"datastring="+data, success: function(d){ console.log("php response "+d); } }); }); }); 

还有PHP

  

现在这是控制台的输出

  first+name=first&last+name=second&some+detail=third&comments=fourth //output from 1st console.log() statement php response first name=first //output from php 

从上面的语句中可以看出,只有第一个值被回显为什么? 这是否意味着它没有从AJAX中获得全部价值?

谢谢

为什么要将它分配给datastring?

只需添加没有前任的数据字符串即可。

 $.ajax({ type:'POST', url:'php/api.php', data:data, success: function(d){ console.log("php response "+d); } }); 

然后在你的PHP:

  

编辑:修复了php端。 谢谢! 虽然没有固定!

我建议你,不要在url放任何()

  $.ajax({ type:'POST', url:'php/api.php', data:{data : $("#Form").serialize()}, //<---You can put the directly here success: function(d){ console.log("php response "+d); } }); 

并在php文件中再次从echo($data);删除() echo($data); 在使用$_POST['data'];

  

试试这个,看看是否有帮助。