AJAX向后台传输数//1 直接在url中传递
$.ajax({
type: "POST",
url: "/testAjax/addUser?id=1&name=zhangxiaofan&sex=male",
success:function(data){
//TODO
}
});
//2 html页面from表单序列化
var formData = $("#form").serialize();
$.ajax({
type: "POST",
url: "/testAjax/addUser",
data: formData,
success:function(data){
//TODO
}
});
//3 拼接data字符串
var formData = $("#form").serialize();
$.ajax({
type: "POST",
url: "/testAjax/addUser",
data: "id=1&name=zhangxiaofan&sex=male",
success:function(data)
}
});
//4 简单的js对象
var userData = {
id:1,
name:zhangxiaofan,
sex:male
};
$.ajax({
type: "POST",
url: "/testAjax/addUser",
data: userData, //或者data:{id:1,name:zhangxiaofan,sex:male}
success:function(data){
//TODO
}
})
拼接data法详解:
http://simple.logphp.com/?a=url&k=6668b1fc&u=aHR0cDovL3d3dy5jbm
时间: 2024-11-08 00:59:08