While playing with the profiling feature of FireBug I found an interesting thing! When using MS Ajax to perform Ajax it takes approx 500+ calls to a simple server side method. The calls go deep into the MS Ajax framework and invoke different methods. However, if we use JQuery to make the same call it will only take <20 calls.
Here is the code for the MS AJAX:
<asp:ScriptManager ID="sm1" runat="server">
<Services>
<asp:ServiceReference InlineScript="false" Path="~/AjaxService.asmx" />
</Services>
</asp:ScriptManager>
And here it the getCustomer method:
function getCustomer()
{
console.profile("start");
DemoScreenScrape.AjaxService.GetCustomer(function(response)
{
var customer = response;
alert(customer);
});
console.profileEnd();
}
And here is the JQuery API Ajax call:
function getCustomer()
{
console.profile("start");
$.ajax({
type: "POST",
contentType:"application/json",
url: "AjaxService.asmx/GetCustomer",
data: "{}",
dataType:"json",
success: function(response)
{
var customer = eval('(' + response.d + ')');
alert(customer.FirstName);
alert(customer.LastName);
}
});
console.profileEnd();
}
The console.profile("start") marks the starting point of the profiling and console.profileEnd() marks the end point of the profiling. This means that all the calls between the console.Profile("start") and console.profileEnd() will be captured in the FireBug profiler.
Here is the reading from the FireBug profiler when MS AJAX was used to call the server side method.

And here is the call to the same server side method using JQuery API:

So, which Ajax framework would you use in your next application?