Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax.BeginForm: disable button while loading

Got a working AJAX form:

@using (Ajax.BeginForm(...))

I want to disable the button while result is loading. If I use this:

$("#submit").click(function () { $("#submit").button().attr('disabled', true).addClass('ui-state-disabled'); })

It disables the button, but form doesnt send anything to the controller. How can I fix that? (and yes, I barely know how to use JS)

like image 823
Wonder Avatar asked Dec 27 '22 05:12

Wonder


1 Answers

This would do the trick:

$(document).ajaxStart(function () {
    $("#submit").prop("disabled", true);
});

And then if you need to make it enabled when done:

$(document).ajaxStop(function () {
    $("#submit").prop("disabled", false);
});
like image 197
Nacho Avatar answered Jan 14 '23 21:01

Nacho