简体   繁体   中英

jQuery vs MicrosoftAjax in ASP.NET MVC

Under what circumstances would you use MicrosoftAjax over jQuery in an ASP.NET MVC application?

According to Scott Cate in this podcast Object Oriented AJAX with Scott Cate MicrosoftAjax is good for sending and retrieving data to and from the server. And jQuery is good for manipulating your data via the DOM once it arrives at the client. Yet, with a simple form plugin for jQuery you can send and retrieve data with jQuery quite easily. Often with a single line of code.

So I'm wondering what the difference is between MicrosoftAjax and jQuery within ASP.NET MVC?

Go with jQuery - even Microsoft has seen the error of their ways. The next version of Visual Studio will include jQuery and support it with intellisense. You're also entirely correct regarding the simple plugin. MS Ajax, while sometimes easier to work with initially, is slow and bloated.

I have tried to use both more or less side by side.

The builtin ajax helpers works fine.

But jquery has a smaller footprint and is more transparent in use.

And when using the ajax helpers I get immediate results but no sense of what goes on behind the scenes

Besides If you have to bridge over into jquery in order to extend your ajax scenario, you might as well start there.

jQuery is lighter-weight, easier to integrate into standard javascript functions, and has great community support. MS Ajax is heavy, but I suspect they are rewriting everything AJAX.

Just be sure to use the jQuery.ajax function and not jQuery.get - its more verbose, but vital for error handling.

Don't skimp on error handling code just because jQuery.get() is easier. It may work on your tests, but you need some kind of error handling for the many cases it wont work.

I'm really not sure why get doesn't have error handling, but here's a quote from the jQuery documentation for get:

This is an easy way to send a simple GET request to a server without having to use the more complex $.ajax function. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code). If you need to have both error and success callbacks, you may want to use $.ajax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM