Skip to content

Instantly share code, notes, and snippets.

@ethan-deng
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethan-deng/cc538bcd07ed3308a4af to your computer and use it in GitHub Desktop.
Save ethan-deng/cc538bcd07ed3308a4af to your computer and use it in GitHub Desktop.
jQuery ajax and ASP.NET Web Services and Web API 2.0

jQuery ajax and ASP.NET Web Services and Web API 2.0

  1. Web Services

Get data

$.ajax({
  type: "POST",
  url: "ServiceName.asmx/WebMethodName",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json"
})
.done(function(result){

})
.fail(function(error){

});

Post data

$.ajax({
  type: "POST",
  url: "ServiceName.asmx/WebMethodName",
  //Web emthod should have one parameter "person".
  data: "{person:{'fname':'dave','lname':'ward'}}",
  contentType: "application/json; charset=utf-8",
  dataType: "json"
})
.done(function(result){

})
.fail(function(error){

});

Web emthod should have one parameter "person".

  1. Web API 2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment