It seems that ASP.NET AJAX is rather heavy-handed and carries hefty performance penalties as compared to the simpler and more straightforward jQuery.
JSON Serialized Web Service
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
System.Web.Script.Services.ScriptService]
public class dummyWebservice : System.Web.Services.WebService
{
[WebMethod()]public string HelloToYou(string name){return "Hello " + name;}
[WebMethod()]public string sayHello(){return "hello ";}
}
Remember to include [System.Web.Script.Services.ScriptService] so that the service is made available to Javascript clients.
JQuery .ajax command
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/WebMethodName",
data: "{}",
dataType: "json"
});
You need to specify the contentType's value as application/json; charset=utf-8 and the dataType as json
to make a JQuery AJAX call.Remember to pass in data: "{}"
If you need to pass in certain params, use
data: "{username:'" + escape(userID) + "'}"
-- Need to escape() the userID so that the backslash (\) is not stripped when passed to AJAX
Monday, June 27, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment