我的脚本看起来像这样。是的,它来自一个插件。不,我对 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 吗?