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?
<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?
To enable, you can set the
disabled
property tofalse
.I would also change your code that disables it to;
From the jQuery docs:
Use
instead of