Ajax-PHP无法正常工作 [英] Ajax-PHP not working correctly

查看:93
本文介绍了Ajax-PHP无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AJAX-PHP错误再次让我感到困惑。现在问题是什么?
我将使用AJAX将一些表格数据从HTML发送到PHP,(我正在使用jQuery)然后使用这些数据,在PHP中使用它并给出一些结果。

Ajax调用成功完成,但问题是并非所有数据都被发送到PHP,而是一些数据丢失如果我正确解释它

jQuery / Ajax代码

The AJAX-PHP bug has bit me again.Now here's the problem
I am to send some form data from HTML to PHP using AJAX,(I'm using jQuery for this) and then use that data, play with it in PHP and give some result.
The Ajax call is made successfully, but the issue is that not all data is being sent to PHP that is some data goes missing if I interpreted it correctly
The jQuery/Ajax Code

$(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

<?php
   $data=$_POST['datastring'];
   echo($data);
?>

现在这里是控制台的输出

Now here's the output from the console

     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的全部价值?

As you can see from the above statement only the first value is echoed why? Does it mean it did not recieve the full value from AJAX?

谢谢

推荐答案

为什么要将它分配给datastring?

Why are you assigning it to datastring?

只需添加没有前任的数据串。

Just add the datastring without the predecessor to it.

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

然后在你的php中:

<?php print_r($_POST); ?>

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

fixed the php side. Thanks! unfixed it though!

这篇关于Ajax-PHP无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆