Ajax调用中出现404错误

时间:2014-12-11 07:32:47

标签: jquery ajax

当我尝试使用以下代码对webAPI进行ajax调用时,大多数情况下它返回404错误。

$.ajax({
    url: Url,
    method: "get",
    contentType: 'application/json; charset=UTF-8',
    data: { "a": a, "b": b, "date": date in yyyy-mm-dd},
    dataType: 'json',
    crossDomain: true,
    async: false,
    timeout: g_TimeOut,
    success: function (data) {
       //success
    },
    error: function (xhr, ajaxOptions, thrownError) {
        var strResponse = "";
        strResponse = ajaxExceptionHandling(xhr, ajaxOptions);
        //Do Something
    }
});

当我试图将restclient称为

时,同样的事情
Url?a=a&b=b&date=yyyy-mm-dd

它提供了正确的数据。如果我错过任何东西,你能否纠正。

请求和响应标头

请求

User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)
 Chrome/39.0.2171.71 Safari/537.36
 Content-Type: text/plain; charset=utf-8 
 Accept: */*
 Accept-Encoding: gzip, deflate, sdch
 Accept-Language: en-US,en;q=0.8

响应

Cache-Control: no-cache 
Pragma: no-cache 
Content-Type: application/json; charset=utf-8 
Expires: -1 
Server: Microsoft-IIS/7.5 
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 11 Dec 2014 07:55:28 GMT 
Content-Length: 10701 

1 个答案:

答案 0 :(得分:0)

尝试这个

 data: JSON.stringify( {"Url":{ "a": a, "b": b, "date": date in yyyy-mm-dd}})

并删除此部分

contentType: 'application/json; charset=UTF-8'