JQuery的Ajax函数在chrome中运行,但在firefox中返回404

我正在使用中央ajax函数将ajax Post请求发送到服务器。 这是函数的代码:

function postJson(url, jsObj, whenSuccess, whenError){ $.ajax({ type: "post", headers: { "Accept": "application/json, text/javascript, */*; q=0.01", "Content-Type": "application/json, text/javascript, */*; q=0.01" }, dataType: "json", url: url, data: JSON.stringify(jsObj), success: function(result){ if(whenSuccess !== undefined){ whenSuccess(result); } }, error: function(xhr){ if(whenError !== undefined){ whenError(xhr.status); } } }); } 

当我尝试运行我的应用程序时,它在chrome中工作正常,但在firefox中它会抛出404.当接受或内容类型未设置为JSON时,我的REST服务助手返回404 …所以我认为firefox可能不会添加标题但是当我查看发送的请求时:

 Request URL: http://localhost:9081/api/1/localize/validation.json Request Method: POST Status Code: HTTP/1.1 404 Not Found Request Headers 08:40:10.000 X-Requested-With:XMLHttpRequestUser-Agent...... Referer:http://localhost:9081/kportal/ Pragma:no-cacheHost:localhost:9081 Content-Type:application/json, text/javascript; charset=UTF-8, */*; q=0.01 Content-Length:2 Connection:keep-alive Cache-Control:no-cache Accept-Language:en-US,en;q=0.5 Accept-Encoding:gzip, deflate Accept:application/json, text/javascript, */*; q=0.01 

您可以看到已设置必要的标头。 我仍然在Firefox中获得404而不是Chrome。

有什么想法吗?

试试这个,

 function postJson(url, jsObj, whenSuccess, whenError){ $.ajax({ type: "post", contentType: "application/json; charset=utf-8", accepts: { xml: 'text/xml', text: 'text/plain' }, dataType: "json", url: url, data: JSON.stringify(jsObj), success: function(result){ if(whenSuccess !== undefined){ whenSuccess(result); } }, error: function(xhr){ if(whenError !== undefined){ whenError(xhr.status); } } }); } 

请参阅jQuery ajax接受attrib的重点是什么? 它真的做了什么吗?

阅读http://api.jquery.com/jquery.ajax/