Updated: jQuery to C# – AJAX (with data)

[WebMethod]
public static string testingWebMethod(string name) {

  //Do something with name? 

  string someString = "Woah";

  return someString;
}
var dataToSend = JSON.stringify({
  "name": "foo"
});

$.ajax({
  type: "POST",
  url: "page.aspx/testingWebMethod",
  dataType: "json",
  data: dataToSend,
  contentType: "application/json",
  success: function(response) {
    alert(response.d);
  },
  error: function(err) {
    alert(err.d);
  }
});
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s