Try this,
This Code will check for any executing ajax request before making a new ajax request. You can subscribe OnSuccess, OnFailure callbacks also :
@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 a jquery alternative (so you don't need that 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 - to give some visual effect to the link while loading
$.get('@Url.Action("ajaxactions")', function(data) {
$('#content').append(data);
$(this).removeClass('someClass');
isExecuting = false;
});
});
@Ajax.ActionLink()codecode@Ajax.ActionLink("Click Me", "ajaxactions", new AjaxOptions { UpdateTargetId = "content", HttpMethod = "Post", Confirm = "Are you Sure ?", InsertionMode = InsertionMode.InsertAfter, LoadingElementId = "im", OnComplete = "end()", OnBegin = "start()" }, new { @id = "btn", @class = "btn btn-default" })codeOnBeginandOnCompletefunctions, so you could add a javascrip variable (say)var IsExecuting = false;, then inOnBeginif itstrue, cancel the ajax call, otherwise set it totrue. Then inOnComplete, set it to false. The user will still be able to click it but it wont do anything. The other option would be jquery (which is better anyway)OnBeginis called before the ajax call to the server, and it can returnfalseto cancel the ajax