ajax post请求在IE和Chrome上的处理方式不同

时间:2012-07-22 15:18:20

标签: jquery ajax apache post

$("#submitbutton").button().click(function() {
    var request = $.ajax({
    type: "post",
    url: "mmm.php",
    data:"abc=abcdefghijklmnopqrstuvwxyz",
    success:function(data){ alert("success: " +data); },
    error:function(data){ alert("error "+data); },
    statusCode:{
        200:function(){alert("200");},
        304:function(){alert("304");},
        404:function(){alert("404");}},
    isModified:function(){alert("Something was modified");}
});

IE9上的这篇文章正确回复。在chrome上,它会生成错误警告,其中包含以下内容:“error [Object] [Object]”

Chrome控制台显示没有错误,服务器回复:

IE的

  

10.0.0.4 - - [22 / Jul / 2012:18:00:22 +0300]“GET /development-bundle/ui/jquery.ui.button.js HTTP / 1.1”200 11342“http:// xxxx.xxxx.net/first.html“”Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 6.1; WOW64; Trident / 5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0 .30729; Media Center PC 6.0; .NET4.0C)“

对于Chrome:

  

10.0.0.4 - - [22 / Jul / 2012:18:08:34 +0300]“GET /development-bundle/ui/jquery.ui.button.js HTTP / 1.1”304 - “http:// xxxx.xxxxxx.net/first.html?” “Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 536.11(KHTML,像Gecko)Chrome / 20.0.1132.57 Safari / 536.11”

知道为什么chrome会在'first.html'之后添加一个问号而IE却没有?它导致apache服务器返回304,将Chrome视为错误

谢谢

1 个答案:

答案 0 :(得分:1)

您希望首先修复您希望传递给服务器的jSon ..它当前不正确..将其更改为以下内容然后尝试。

$("#submitbutton").click(function() {
    var request = $.ajax({
    type: "post",
    url: "mmm.php",
    data:{abc:"abcdefghijklmnopqrstuvwxyz"},
    success:function(data){ alert("success: " +data); },
    error:function(data){ alert("error "+data); },
    statusCode:{
        200:function(){alert("200");},
        304:function(){alert("304");},
        404:function(){alert("404");}},
    isModified:function(){alert("Something was modified");}
});

我还修改了你的事件绑定,似乎没有button()调用。