-
底層步驟
實例對象
創(chuàng)建HTTP請求
發(fā)送請求
設(shè)置回調(diào)函數(shù)
- 使用jQuery
$.ajax({
"url":"/AjaxDemoServlet",
"type":"POST",
"data":"name="+name+"&pwd="+pwd,
"dataType":"JSON",
"success":callBack,
"error":function () {
alert("驗證時出現(xiàn)錯誤待榔!");
}
});
function callBack(data) {
...
}
$.post({url,data,callBack,dataType};
function callBack(data) {
...
}
$(selector).load(url[,data][,complete]);//加載HTML內(nèi)容
- JSON
var person={"name":"Mary","age":25,"spouse":null};
var nation=["中國","美國","俄羅斯"];
var p=[{"name":"Mary","age":25},{"name":"Bob","age":27}];
//將普通對象轉(zhuǎn)換為JSON對象
先導(dǎo)入jar包
String newsJSON=JSON.toJSONString();