jQuery ajaxForm(options) 应该传递什么给选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1635836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ajaxForm(options) what should be passed to the options?
提问by svk
$(document).ready(function() {
var options = {
target: '#output1', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
};
$('#myForm1').ajaxForm(options);
});
function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
alert('About to submit: \n\n' + queryString);
return true;
}
function showResponse(responseText, statusText) {
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
In the above program what is passed in the option argument?I use the http://jquery.malsup.com/
在上面的程序中,选项参数中传递了什么?我使用http://jquery.malsup.com/
回答by jitter
What is your question?
你的问题是什么?
Please elaborate.
请详细说明。
From the jQuery Form Plugin API Documentation:
ajaxForm
Prepares a form to be submitted via AJAX by adding all of the necessary event listeners. It does not submit the form. Use ajaxForm in your document's ready function to prepare your form(s) for AJAX submission. ajaxForm takes zero or one argument. The single argument can beeither a callback function oran Options Object. Chainable: Yes.
Note: You can pass any of the standard $.ajax options to ajaxForm
ajax表单
通过添加所有必要的事件侦听器,准备要通过 AJAX 提交的表单。它不提交表单。在文档的就绪函数中使用 ajaxForm 为 AJAX 提交准备表单。ajaxForm接受零个或一个参数。单个参数可以是任一个回调函数或一个 选项对象。可链接:是的。
注意:您可以将任何标准的 $.ajax 选项传递给 ajaxForm
回答by Shubham Monga
target - [#outout1] is the Div which you want to reload.
目标 - [#outout1] 是您要重新加载的 Div。
beforSubmit - action you want to perform before reload
beforSubmit - 您要在重新加载之前执行的操作
success - action you want to perform after reload
成功 - 您要在重新加载后执行的操作
回答by rajesh kakawat
The 'beforeSubmit' callback is invoked with three arguments: the form data in array format, the jQuery object for the form, and the Options Object passed into ajaxForm/ajaxSubmit.
'beforeSubmit' 回调使用三个参数调用:数组格式的表单数据、表单的 jQuery 对象和传递到 ajaxForm/ajaxSubmit 的选项对象。