Click here to Skip to main content
15,886,106 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hello Friends i have start learning JSON.

I create a WEB SERVICE(asmx) in ASP.NET i used JSON in it.
I want to call webmethods with jQuery, JavaScript or Ajax.

Now i want to call my Method taking 2 or more parameter.


so i don't know how to use this i m beginner of Ajax,jQuery.
Posted

Take a look at this, perfect fit for what you are asking for.

How to call a Web Service from client-side JavaScript using ASP.NET AJAX[^]

Also, you can refer to Client-Side Web Service Calls with AJAX Extensions[^]
 
Share this answer
 
hi,
You can achive this by Jquery ajax. Lets say you have a web method Report1 that takes 2 parameter fromDate and toDate.

C#
[WebMethod]
public static String Report1(String fromDate,String toDate)
{
  //function body
}


now you can call the above method by jquery ajax
$.ajax({
 type: "POST",
 url: "default.aspx/Report1",
 data: "{fromDate:'1/1/2011',toDate:'6/30/2011'}"
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 beforeSend: function () { $("#wait").show(); },
 complete: function () { $("#wait").hide(); },
 success: function (msg) {
	//msg.d contains the returned JSON
 },
 error: function () { }
});


check here[^] for code samples
 
Share this answer
 
Comments
Monjurul Habib 21-Jun-11 17:37pm    
5++,nice detail with link..proposed as answer.
jQuery's Ajax methods return a superset of the XMLHTTPRequest object. This jQuery XHR object, or "jqXHR," returned by $.getJSON() implements the Promise interface, giving it all the properties, methods, and behavior of a Promise.

Please follow the link, hope it will help you.

http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/[^]

http://vincenthomedev.wordpress.com/2009/02/10/consuming-an-aspnet-web-service-or-page-method-using-jquery/[^]
 
Share this answer
 
Comments
Shahriar Iqbal Chowdhury/Galib 21-Jun-11 16:44pm    
nice
Monjurul Habib 21-Jun-11 17:36pm    
thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900