ajax傳輸數據
阿新 • • 發佈:2017-05-10
傳遞 log function aof 傳輸數據 fan .com rom htm
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
ajax傳輸數據