jQuery 1.3.2,ASP.NET 2.0.对PageMethod(WebMethod)进行Ajax调用将返回整个/整个页面,而不仅仅是响应.页面方法上的断点表示它永远不会命中.我的方法上有[WebMethod]属性,它是isPUBLIC静电,返回字符串,不接受参数.我甚至try 在班级的顶端添加[ScriptService],看看是否有帮助,但没有.
我看过这篇文章Jquery AJAX with ASP.NET WebMethod Returning Entire Page,它有和我一样的症状,但是我还是有问题.我读了"http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/",感觉就像是顺着这条路走到了T,但还是没有运气.
我打的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,只是为了好玩,看看它是否有帮助,但没有运气.
有什么建议吗?