jquery Ajax是對 XMLHttpequest 對象的封裝
常用部分
$.ajax({
type: "POST", // 數(shù)據(jù)提交類型
url: "danmu.php", // 發(fā)送地址
data: {word:"abs",username:"啥玩應啊"}, //發(fā)送數(shù)據(jù)
dataType: "json", // 指定返回類型
async: true, // 是否異步
success:function(data){ // 數(shù)據(jù)加載成功之后的回調(diào)函數(shù)
console.log(data);
for(var i in data){
$("#show").html($("#show").html() + data[i] + "
");
}
}
});
load 參數(shù) 加載的頁面地址 加載完成之后 自動添加到 執(zhí)行這個方法的元素的上面
$("#show").load("danmu.html");
$.get("danmu.php",{},function(data,status){
console.log(arguments);
console.log(data);
},"json");
$.post("danmu.php",{},function(data,status){
console.log(arguments);
console.log(data);
},"json");