$.ajax({
type: "POST",
url:"ajax.php",
data:$('#formID').serialize(),// 要提交的表单
success: function(msg) {alert(msg);},
error: function(error){alert(error);}
});
serialize()序列化表单实例:
>
$(function(){
$("#button").click(function(){
alert($("#formID").serialize());
});
});
>
姓名
职位
将form中的值转换为键值对:
// 如:{Name:'摘取天上星',position:'IT技术'}
// ps:注意将同名的放在一个数组里
function getFormJson(form) {
var o = {};
var a = $(form).serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
键值对方式的AJAX调用: