Sergey Plakhinin
Sergey Plakhinin

Reputation: 1

Disable button after ajax Success

I need to disalble submit button after ajax forever! But when I reload the page submit button is active(

function submitConfirmAjaxList(e){
    var url = "<?php echo $this->getUrl('wedding/gifts/confirmList') ?>";
    var getTransferId = '<?php echo $checkTransferId?>';
    var getCurrentCustomerId = '<?php echo $getCurrentCustomerId?>';
    var confirmResponse = 1;
    var disalleButton = $('confirmButton').setAttribute('disabled', 'disabled');

    new Ajax.Request(url, {
        method:'post',
        parameters: {
            getTransferId : getTransferId,
            getCurrentCustomerId : getCurrentCustomerId,
            confirmResponse : confirmResponse
        },
        requestHeaders: {Accept: 'application/json'},
        onSuccess: function(transport) {
            location.reload();
            e.disable();

        }
    });

}
__('Сonfirm the list')?>" class="button" onclick="submitConfirmAjaxList(this)">__('confirm the list')?>

Upvotes: 0

Views: 636

Answers (5)

Vertika Srivastava
Vertika Srivastava

Reputation: 167

Use this in AJAX Success:

$(".class").attr('disabled','disabled');

Upvotes: 0

Siddharth Vaghasia
Siddharth Vaghasia

Reputation: 208

After sucess, put some value in cookie, validaty of cookie should be till current session, on page load (may be document.ready) check if cookie value is specific to which you stored then disable the button with jquery.

Upvotes: 0

Ben Win
Ben Win

Reputation: 840

You could easily accomplish that if you would delete your location.reload();. The idea of ajax is the asynch call, which is executed and processed without reloading the entire page. That said you can just put $('#confirmButton').attr('disabled', 'disabled'); in your onSuccess: function(transport) {} method and you should be fine

Upvotes: 1

Quentin
Quentin

Reputation: 943564

If you reload the page then you have a new page which doesn't maintain state from any previous changes you made with JavaScript.

You need to store something on the server (e.g. in session data or the user's account data in the database) that indicates the submit button should be disabled.

Then your server side code should include a disabled attribute in the button when the page loads.

Upvotes: 0

Vinie
Vinie

Reputation: 2993

Use this

$('#button_id').prop('disabled', 'disabled');

Upvotes: 0

Related Questions