hi guys,
Well I like to share one more experiment with you that is how to call a webservice from your javascript(jquery). For that again you need to have an asp.net ajax enable website.
Lets first examine what are the requiments for webservice if we need to call it from javascript well after having asp.net ajax enable website first is you should mark your serverice as [ScriptService] what it does it will make all the methods/functions of your webservice to be accessable from javascript code and it also serialise your webservice response using JASON .
By default asp.net web services use soap for communication scriptservice marker make your webservice to use JASON.
Now lets defien the method in our webservice which we want to be accessable by our javascript code.
|
|
That’s it now lets move to client side code.
|
|
In above javasrcipt code we are making an ajax post request we set contentType to “application/json; charset=utf-8” and dataType to “json” and passing a=1,b=2 as are data input parameters note that varriables name are same as verriables declared in webservice’s function AddingNumbers input parameters.
Please read articles from following links to know more and have a strong background.
http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/
http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
http://www.keithrousseau.com/blog/2008/05/using-jquery-json-with-aspnet/