Reputation: 970
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...
Upvotes: 2
Views: 152
Reputation: 7111
Your webmethod UpdateEmeaData
needs to be static for this to work.
[WebMethod]
public static void UpdateEmeaData(string postData)
{
}
Upvotes: 2