Ajax表单只工作一次 [英] 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?
<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>
非常感谢。
修改
回调函数在结尾死了()
。我读的是仅仅为了能够检索功能的输出。这是否结束AJAX呢?
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 to false
.
jQuery('#submit-ajax').prop('disabled', false);
我也会改变你的code,禁用它;
I would also change your code that disables it to;
jQuery('#submit-ajax').prop('disabled', true);
从 jQuery的文档:
()方法应用于设置禁止,检查了.attr()方法代替的.prop
The .prop() method should be used to set disabled and checked instead of the .attr() method.
这篇关于Ajax表单只工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!