javascript - ASP.Net Mvc Ajax Request in Progress -


i using @ajax.actionlink call controller action in ajax fashion .is there way detect if there ajax request running/pending on page?the functionality want pretty basic i.e. once user clicks link should wait either request succeed or fail.he should allowed click again( generate new request server).

i have disabled link not that(i guess href cant disabled)

try this,

this code check executing ajax request before making new ajax request. can subscribe onsuccess, onfailure callbacks :

@ajax.actionlink("home", "index", "home", new ajaxoptions {      onbegin = "return onbegin();",     oncomplete = "oncomplete",     updatetargetid = "article_site" }) 

and then:

var request_executing = false; function onbegin() {     if (request_executing == true) {return false ;}     request_executing = true;     return true; }  function oncomplete() {     request_executing = false; } 

or jquery alternative (so don't need bloated jquery.unobtrusive-ajax.js file)

@html.actionlink("click me", "ajaxactions", null, new { id = "btn", @class = "btn btn-default" })  var isexecuting = false; $('#btn').click(function(e) {   if(isexecuting) {     e.preventdefault();     return;   }   isexecuting = true;   $(this).addclass('someclass'); // optional - give visual effect link while loading   $.get('@url.action("ajaxactions")', function(data) {     $('#content').append(data);     $(this).removeclass('someclass');     isexecuting = false;   }); }); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -