我的脚本看起来像这样。 是的,它来自插件。 不,我对 ajax 不太满意。
如何让此表单刷新并能够在首次提交后再次接受输入?
<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>
非常感谢。
编辑:
回调函数以die()
结束。我读到这只是为了能够检索函数的输出。这是否也结束了 AJAX?
最佳答案
要启用此功能,您可以将 disabled
属性设置为 false
。
jQuery('#submit-ajax').prop('disabled', false);
我还会更改您的代码以禁用它;
jQuery('#submit-ajax').prop('disabled', true);
来自jQuery docs :
The .prop() method should be used to set disabled and checked instead of the .attr() method.
关于php - Ajax 表单只能工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17191355/