interviews.dotnetthread.com

↑ Grab this Headline Animator

Monday, March 2, 2009

Calling Page Methods and Web Services directly using jQuery.

For calling Ajax Page Methods from Javascript using jQuery use the below jQuery method to set type, url, input data empty braces if no input data is available to avoid errors. Data transfer will done in JSON format.


$.ajax({
type: "POST",
url: "PageName.aspx/WebMethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
// Your logic here
}
});



To consume Webservice in Javascript using jQuery is similar to above where we will pass the data as JSON format string.


$.ajax({
type: "POST",
url: "ServiceName.asmx/WebMethodName",
data: "{'name':'anil','gender':'male','age':'23'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
// Your logic here
}
});

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles