大家好,我在我的页面上使用 jQuery 表单插件来处理表单提交(可在http://malsup.github.com/jquery.form.js找到),但现在必须切换到使用纯基于 jQuery AJAX 的方法(没有使用任何表单插件,但我可以使用 jQuery)。实现这一目标的最佳方法是什么?我很难翻译它。理想的解决方案是什么样的?
这是我在下面使用的代码:
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
target: '#result',
beforeSubmit: showRequest,
success: showResponse
};
// bind to the form's submit event
$('#booking').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
// alert('About to submit: \n\n' + queryString);
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
$('#last-step').fadeOut(300, function() {
$('#result').html(responseText).fadeIn(300);
});
}