2

I'm using .NET 4.5, I used this code from a WCF service to Javascript this worked fine. Now I can't seem to figure out how to send data back to the aspx page also with Ajax. What am I doing wrong?

Javascript called when pressing a button:

function sendEmeaDataToWcf(object) {
    $.ajax({
        type: "POST",
        url: "EditFeedEmea.aspx/UpdateEmeaData",
        data: JSON.stringify({ postData: "Test" }),
        processData: false,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        success: function() {
            console.log("Emea Data loaded");
        },
        error: showError
    });
}

The code in the code behind:

[WebMethod]
public void UpdateEmeaData(string postData)
{

}

He doesn't even get to the webmethod. I get a 500 error (jqXhr.status == 500). Receiving data from the same page works well. I also tried to remove processData, dataType, async, charset. Still nothing...

2
  • 1
    You could check the answer of your aspnet server in the network tab of chrome dev tools, would help. Commented Dec 30, 2013 at 16:33
  • 1
    500 error means server side internal error. First check about the "static" keyword for webmethod. As Florian tells, do use Chrome Developer options or Firebug to check the details of error. Commented Dec 30, 2013 at 17:07

1 Answer 1

2

Your webmethod UpdateEmeaData needs to be static for this to work.

[WebMethod]
public static void UpdateEmeaData(string postData)
{

}
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.