我看到了这篇文章Jquery AJAX with ASP.NET WebMethod Returning Entire Page,它有相同的症状,但我仍然有问题。我读了http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/,感觉我一字不漏地遵循了它,但仍然没有运气。
我正在进行的jQuery调用是:
jQuery.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: '{}',
dataType: 'json',
url: 'MyPage.aspx/SomePageMethod',
success: function(result){
alert(result);
}
});
根据FF3中的Firebug,请求/响应头如下所示:
Response Headers
Server ASP.NET Development Server/8.0.0.0
Date Tue, 24 Feb 2009 18:58:27 GMT
X-AspNet-Version 2.0.50727
Cache-Control private
Content-Type text/html; charset=utf-8
Content-Length 108558
Connection Close
Request Headers
Host localhost:2624
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6
Accept application/json, text/javascript, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Content-Type application/json; charset=utf-8
X-Requested-With XMLHttpRequest
Referer http://localhost:2624/MyApp/MyPage.aspx
Content-Length 2
Cookie ASP.NET_SessionId=g1idhx55b5awyi55fvorj055;
我只是为了好玩在页面上添加了一个 ScriptManager,看看是否有帮助,但没有什么效果。
有任何建议吗?