Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET AJAX vs jQuery in ASP.NET MVC

Which one is better to use in ASP.NET MVC?

like image 939
emalamisura Avatar asked Apr 22 '09 14:04

emalamisura


People also ask

Which is better jQuery or AJAX?

jQuery uses ajax for many of its functions, but it nothing else than a library that provides easier functionality. With jQuery you dont have to think about creating xml objects ect ect, everything is done for you, but with straight up javascript ajax you need to program every single step of the ajax call.

Can we implement AJAX using jQuery in MVC?

Using AJAX In ASP.NET MVC. Implementation of Ajax can be done in two way in ASP.Net Application: using Update Panel and, using jQuery.

What is the difference between AJAX and jQuery?

AJAX is a web development technique for making asynchronous calls to the server. jQuery is a JavaScript library for designing and make some web development tasks easy. It makes it possible to run javascript outside of the browser. It works on the browser or outside the browser also.

Can we use AJAX in MVC?

The MVC Framework contains built-in support for unobtrusive Ajax. You can use the helper methods to define your Ajax features without adding a code throughout all the views. This feature in MVC is based on the jQuery features. To enable the unobtrusive AJAX support in the MVC application, open the Web.


2 Answers

Personally I prefer jQuery for the following reasons:-

  1. The plug-in community is far more varied and attracts developers from a broad range of backgrounds (not just the MS stack). For MS-AJAX you're pretty much constrained to the clientside AJAX control toolkit for your UI widgets at the moment.
  2. I find the jQuery API far more applicable common clientside tasks than that offered by MS AJAX
  3. Given the lack of WebForms smoke and mirrors going on in MVC you sometimes need a firm control over the DOM to do certain things, the CSS selector engine offered by jQuery really helps you do this.

In terms of what MS AJAX offers you in MVC, it can do a lot for you in terms of giving you a quick way to "AJAXify" forms and links, but as far as I'm concerned adding 90kb worth of javascript to do that isn't really worth it when the equivalent calls in jQuery (e.g $.get, $.post, $(element).load) are relatively easy to use.

like image 71
John Foster Avatar answered Sep 22 '22 12:09

John Foster


Personally, despite the HtmlHelper support for ASP.NET Ajax, I find jQuery ajax in conjunction with the JQuery forms plugin to be the nicest way to do ajax form posts in ASP.NET MVC.

e.g. with a jquery call on an html product list page with a form for each product allowing the item to be added to a basket, a single line of jquery code can 'ajaxify' all the forms on the page

$(".productListItem form").ajaxForm({ target: '#extraInfoSection' }); 

combined with a simple 'IsAjaxRequest' property on a controller base class that checks the headers:

Request.Headers["X-Requested-With"] == "XMLHttpRequest" 

and some logic in the Controller to return the correct response type:

return IsAjaxRequest ? (ActionResult) View("BasketPartial", basket) : new RedirectBackToReferrerActionResult(); 

you have a form that works even with javascript turned off and no ASP.NET Ajax involved.

like image 30
Steve Willcock Avatar answered Sep 25 '22 12:09

Steve Willcock