Ajax form only work one time

My script is looking like this. Yes, it is from a plugin. No, I’m not comfortable with ajax.

How can I get this form to refresh and be able to take input once more after first submit?

Read More
<script>
jQuery(document).ready(function() { 
    var options = { 
        target: '#ps_output',      // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,     // pre-submit callback 
        success:       showResponse,    // post-submit callback 
        url:           '<?php echo $link; ?>'         // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php     
}; 

    // bind form using 'ajaxForm' 
    jQuery('#thumbnail_upload').ajaxForm(options); 
});

function showRequest(formData, jqForm, options) {
    //do extra stuff before submit like disable the submit button
    jQuery('#ps_output').html('Sending...');
    jQuery('#submit-ajax').attr("disabled", "disabled");
}

function showResponse(responseText, statusText, xhr, $form)  {
    //do extra stuff after submit
    jQuery('#submit-ajax').attr("enabled", "enabled");
}
</script>

Thanks alot.

EDIT:

The callback function ends in die(). I read that was simply for being able to retrieve the output from the function. Does that end AJAX too?

Related posts

Leave a Reply

2 comments

  1. To enable, you can set the disabled property to false.

    jQuery('#submit-ajax').prop('disabled', false);
    

    I would also change your code that disables it to;

    jQuery('#submit-ajax').prop('disabled', true);
    

    From the jQuery docs:

    The .prop() method should be used to set disabled and checked instead of the .attr() method.