1

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);
        }
    });
}

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

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

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

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.

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

1 Answer 1

9

Fixed,

Change

url: "default.aspx/LoadNewsItems",

To

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

It has to do with the URL Routing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.