相关疑难解决方法(0)

使用jQuery调用ASP.NET PageMethod/WebMethod - 返回整个页面

jQuery 1.3.2,ASP.NET 2.0.对PageMethod(WebMethod)进行AJAX调用会返回完整/整个页面,而不仅仅是响应.页面方法上的断点显示它永远不会被击中.我的方法有[WebMethod]属性,它 public static,返回string并且不接受params.我甚至尝试在我的班级顶部添加[ScriptService]以查看它是否有帮助,但事实并非如此.

我已经看到这篇帖子Jquery AJAX与ASP.NET WebMethod返回整个页面有相同的症状,但我仍然有问题.我读了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);
    }
});
Run Code Online (Sandbox Code Playgroud)

根据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 …
Run Code Online (Sandbox Code Playgroud)

asp.net jquery web-services asmx pagemethods

36
推荐指数
4
解决办法
6万
查看次数

标签 统计

asmx ×1

asp.net ×1

jquery ×1

pagemethods ×1

web-services ×1