Ajax语法错误

时间:2015-02-19 10:39:57

标签: javascript ajax

请在我的ajax代码中需要帮助,我在ajax中发送数据时出错。 它给我一个数据语法错误,我试图改变它很多次,我没有成功

这是我的代码:

$.ajax({
        type: "POST",
        url: "customer.php",
        data: {content : '"msisdn = '+mob+'"' , type : 'GetCustomer' }, 
        dataType: "json",
                  success:function(data){
          alert(data);        
        },
         error: function(error) { 


                }
        }); 

2 个答案:

答案 0 :(得分:1)

您的数据属性中没有语法错误(请参阅http://jsfiddle.net/nwjrf0jy/)。

如果您在激活某些调试工具的情况下查看该页面,则可以看到对customer.php的请求。如果是jfiddle,则返回404错误。

我的猜测是,您的customer.php不会返回有效的JSON内容。这包括将响应标头设置为application/json

请注意,由于您的额外双引号,$_POST['content']将为'"msisdn = 12345"'。不知怎的,我不认为你想要那个。

答案 1 :(得分:0)

可能是数据对象中使用的密钥需要包含在小数中。

$.ajax({
    type: "POST",
    url: "customer.php",
    data: {'content' : '"msisdn = '+mob+'"' , 'type' : 'GetCustomer' }, 
    dataType: "json",
              success:function(data){
      alert(data);        
    },
     error: function(error) { 


            }
    });