views:

39

answers:

1

Hi All,

I have a web application that utilises both the MVC Ajax calls: Html.ActionLink() rendering as Sys.Mvc.AsyncForm.handleClick( in the page source

and: jQuery Ajax calls, eg:

$.post()

Now I can easily set a generic Ajax indicator to show and hide when the jQuery is making an Async call using:

  $('#indicatorId').ajaxStart(function() {
                $(this).show();
            }).ajaxStop(function() {
                $(this).hide();
            });

And I can set some functions to show and hide the same indicator by passing values into the constructor of the Ajax.ActionLink constructor and setting OnBegin and OnComplete, but this means that I have to do this EVERYTIME I add a new Ajax.ActionLink to the site.

Is there a better way to do this? Perhaps I could scan the DOM after it's rendered and add the generic events then?

Any thoughts, better examples?

A: 

Unless you've a compelling reason (I've never found one) you shouldn't mix jQuery and MS Ajax into the same site and unless you've a compelling reason you should prefer jQuery. So, no need to use Ajax.* helper methods which tend to pollute the markup with javascript.

Do it the jQuery way, unobtrusively.

Darin Dimitrov
I totally agree with you, and under normal circumstances I wouldn't want to polute a site with two libraries which have a similar end result, although in this case as I am prototyping a site and I found it is quicker to use the MVC Ajax helpers to produce forms that handle Ajax, and jQuery to handle transitions and other Ajax calls outside of forms/actionlinks. I guess I should stop being lazy and use just one method.
Tr1stan
Then you will find that with the `jquery.form` plugin (http://jquery.malsup.com/form/) it is even easier to ajaxify your forms.
Darin Dimitrov