Tom
Tom

Reputation: 16246

Ajax in MVC @Ajax. Helpers and in JQuery.Ajax

I know a bit of Ajax. And now I am learning MVC + JQuery. I want to know if the 2 Ajaxs in MVC Ajax.Helper and JQuery.Ajax are using the same base? Are they the same as the normal Ajax I learned using XMLHttpRequest xhr? If not, what is the preferred way of doing it? I am new to this, and a bit confused, so please don't mind if my question doesn't make sense to you. Thank you, Tom

(edited) I wrote some mvc3 Razor:

<div id="MyAjaxDiv">@DateTime.Now.ToString("hh:mm:ss tt")</div>
@Ajax.ActionLink("Update", "GetTime", new AjaxOptions { UpdateTargetId = "MyAjaxDiv", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" })

When I open up the source code in notepad, I get:

<div id="MyAjaxDiv">06:21:10 PM</div>
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#MyAjaxDiv" href="/Home/GetTime">Update</a>

So, because I have only included ~/Scripts/jquery.unobtrusive-ajax.min.js, the MVC helpers must be using the JQuery to work. I had the impression that they might need the MicrosoftAjax.js, MicrosoftMVCAjax.js ....etc, doesn't look like it now. Are they for MVC2 and aspx pages?

Upvotes: 2

Views: 1563

Answers (1)

Beenish Khan
Beenish Khan

Reputation: 1583

Here's an excerpt from an MVC book,

MVC version 3 introduced support for jQuery Validation, whereas earlier versions relied on JavaScript libraries that Microsoft produced. These were not highly regarded, and although they are still included in the MVC Framework, there is no reason to use them.

JQuery has really become the standard for ajax based requests. You may still use your "XMLHttpRequest xhr" way but Jquery has made it easier to perform the same thing.

Upvotes: 2

Related Questions