怎樣通過ajax提交資料
阿新 • • 發佈:2019-02-13
ajax的出現徹底改變了javascript命運,通過ajax可以直接向伺服器提交資料,有兩種方式:
get方式,資料直接拼接在地址中
post方式,資料由data欄位攜帶
post方式,data中是引數。
$.ajax({
url:"http://localhost/contact2/user/list.do",
type:"post",
dataType:"json",
data:"username=王&order=desc",
success:function(data){
alert("11" );
}
});
get方式,資料在位址列中:
$.ajax({
url:"http://localhost/contact2/user/list.do?username=zhangsan",
type:"post",
dataType:"json",
success:function(data){
alert("11");
}
});