jQuery的serialize()方法的作用。
jQuery官网的API:http://api.jquery.com/
或参照该例子的中文API:http://jquery.cuishifeng.cn/jQuery.post.html
例子:
$("#save").click(function(){
if (checkType()) {
$.post("?pageAction=save", $("#insertForm").serialize(), function(re){
if(re==null){
alert('保存成功!');
window.parent.location.reload(true);
}else{
alert(re);
}
},"json");
}
});
官网解释:
.serialize()
Encode a set of form elements as a string for submission.
编码一组表单元素作为提交字符串。jQuery.post( url [, data ] [, success ] [, dataType ] )
-
urlType: StringA string containing the URL to which the request is sent.
-
dataType: PlainObject or StringA plain object or string that is sent to the server with the request.
-
successA callback function that is executed if the request succeeds. Required if
dataType
is provided, but can benull
in that case. -
dataTypeType: StringThe type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).