通過 jQuery AJAX 方法,您能夠使用 HTTP Get 和 HTTP Post 從遠程服務器上請求文本、HTML、XML 或 JSON- 同時您能夠把這些外部數據直接載入網頁的被選元素中。
多種實現方式: $.ajax $.post $.get 等等
首先看最底層的$.ajax(url,data,function( ){ });
格式如下:
jQuery.ajax({
url: "xxxxx.htm",
data:{" xx":xx,"xx" :"${requestScope.xx}"},
success: function(data) {
if(data!=null){
//alert(data.message);
}
},error: function(XMLHttpRequest, textStatus, errorThrown) {
//alert("異步獲取數據出現異常。");
},complete: function(){
// alert("complete!");
}
});
demo1:
jQuery.ajax({
url: "<%=request.getContextPath()%>/syslog/seeKsLog.htm",
data:{"regid":id,"examid" :"${requestScope.examid}"},
success: function(data) {
if(data!=null){
alert(data.message);
}
},error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("異步獲取數據出現異常。");
} ,complete: function(){
var cont = $("#logDiv").html();
alw(cont);
}
});
$.post() 格式如下:
$.post("xxxxxxx.htm",
{"username": username, "phone": phone,"ts":Math.random()},
function(data){ }