The diary of a .NET Developer, working on an unlaunched startup project. Also, I live and work in Southern Oregon.

Tuesday, January 27, 2009

ASP.NET Ajax vs jQuery.ajax

I love jQuery but ASP.NET Ajax has some great features for calling your own webservices.  Using jQuery to call services is much simpler, and has less going on behind the scenes, but is harder to debug.  ASP.NET Ajax is creating a leaky abstraction for you, and along with that you get intellisense, helpful erorrs, and full visual studio debugging capabilities.

Calling ASP.NET Webservice with jQuery:

type: "POST",
url: "PortfolioService.asmx/AddBenchmarkToCart",
data: '{portfolioId: "'+portfolioId+'", benchmarkId:"' + benchmarkId+ '", position:"'+position+'"}',
contentType: "application/json; charset=utf-8",
dataType: "json"});

  • Simple code: not a lot of behind the scenes magic
  • Efficient: doesn’t load any extra javascript files
  • Hard to debug: it either works or it doesn’t, you get no useful error messages
  • Six lines of code to copy/paste each time

Calling ASP.NET Webservice with ASP.NET Ajax:

<asp:ScriptManager ID="ScriptManager1" runat="server" >
<asp:ServiceReference Path="~/Portfolio/PortfolioService.asmx" InlineScript="false" />
PortfolioService.AddBenchmarkToCart(portfolioId, benchmarkId, position);
  • Intellisense
  • Useful Error Messages
  • Fully functional visual studio debugging
  • Less efficient: includes a small proxy javascript file for your webservice (which the client must download).

For more information on this, see this nice tutorial over on the site.

No comments:

Post a Comment