Chrome 调试器显示名称为“GetPurchaseOrdersComponent”,路径显示为“/Cost”,而 Telerik 网格控件的调用名称为“4485”,路径为“/Cost/GetPurchaseOrders”(它们正在工作)。此外,我调用的类型(在 Chrome 的调试器中查看时)是 text/html,而在工作调用中,它是 application/json。我得到的错误是:“500(内部服务器错误)”。我为此调用定义了与其他调用类似的路由。这是我的代码:
$.ajax({
url: "/Cost/GetPurchaseOrdersComponent",
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
async: true,
data: { id: 1 },
success: function (result) {
$("#ComponentsMultiLevelGrid").html(result);
}
});
[HttpGet]
public string GetPurchaseOrdersComponent(int id)
{
return "some string";
}
更新:
这是有效调用的标题(此调用来自 Telerik 网格):
Request URL:http://localhost:61751/Cost/GetSupplierCatalogs/4485?key=4485&_=1340830508447
Request Method:POST
Status Code:200 OK
**Request Headers** - view source
Accept:text/plain, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:13
Content-Type:application/x-www-form-urlencoded
Cookie:ASP.NET_SessionId=uxn1ctvzcchyrbreymcgz1vl
Host:localhost:61751
Origin:http://localhost:61751
Referer:http://localhost:61751/Transaction/4485
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
X-Requested-With:XMLHttpRequest
**Query String Parameters** - view URL encoded
key:4485
_:1340830508447
Form Dataview URL encoded
page:1
size:5
**Response Headers** - view source
Cache-Control:private
Connection:Close
Content-Length:21
Content-Type:application/json; charset=utf-8
Date:Wed, 27 Jun 2012 20:55:28 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
这是失败的调用的标头(这是 jQuery 调用):
Request URL:http://localhost:61751/Cost/GetPurchaseOrdersComponent?id=1
Request Method:GET
Status Code:500 Internal Server Error
**Request Headers** - view source
Accept:text/plain, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded
Cookie:ASP.NET_SessionId=uxn1ctvzcchyrbreymcgz1vl
Host:localhost:61751
Referer:http://localhost:61751/Transaction/4485
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
X-Requested-With:XMLHttpRequest
**Query String Parameters** - view URL encoded
id:1
**Response Headers** - view source
Cache-Control:private
Connection:Close
Content-Length:10434
Content-Type:text/html; charset=utf-8
Date:Wed, 27 Jun 2012 20:55:25 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319