ASP.NET 4 jQuery的AJAX的WebMethod调用 [英] ASP.NET 4 jquery ajax webmethod call

查看:138
本文介绍了ASP.NET 4 jQuery的AJAX的WebMethod调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET 3.5我有这个JavaScript的网页(Default.aspx的)上:

In ASP.NET 3.5 I had this javascript on a page (default.aspx):

function getMoreNewsItems() {
    $.ajax({
        type: "POST",
        url: "default.aspx/LoadNewsItems",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert(msg.d);
        }
    });
}

通过这背后的code(default.aspx.cs):

With this in the code behind (default.aspx.cs):

[System.Web.Services.WebMethod]
public static string LoadNewsItems() {
    return "test1";
}

我有一个ScriptManager用的EnablePageMethods =真正的在页面上。所有工作的罚款。

I have a ScriptManager on the page with EnablePageMethods=true. All worked fine.

现在该项目升级到ASP.NET 4.0,并使用新的URL路由功能。 Ajax调用不再工作了。在Firebug我看到它返回,而不是XML响应的完整的页面。

Now the project upgraded to ASP.NET 4.0 and is using the new url routing functionality. The AJAX call doesn't work anymore. In FireBug I see it returns the complete page, instead of the XML response.

什么在ASP.NET 4改变了这可能是导致此错误?

What has changed in ASP.NET 4 that could be causing this error?

推荐答案

固定,

修改

url: "default.aspx/LoadNewsItems",

url: '<%= ResolveUrl("default.aspx/LoadNewsItems") %>',

它做的URL路径。

It has to do with the URL Routing.

这篇关于ASP.NET 4 jQuery的AJAX的WebMethod调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆