2024年06月26日 建站教程
jquery有哪些交互方式,下面web建站小编给大家详细介绍一下!
1、利用load实现交互
$("id").load("xx.txt",function(responseTxt,statusTxt,xhr){
if(statusTxt=="success"){
console.log("成功");
}
if(statusTxt=="error"){
console.log("失败:"+xhr.status+":"+xhr.statusTxt);
}
});
2、利用post实现交互
$.get("/json/index", {
name:"xiaomi",
sex:'男'
}, function(data, status) {
console.log(data + ":" + status);
});
3、利用get实现交互
$.get("xx.txt",null,function(data,status){
console.log(data+":"+status);
});
4、利用getJSON实现交互
$.getJSON("/json/index", {
name:"xiaomi",
sex:'男'
}, function(json) {
console.log(json.name);
});
5、利用jQuery.ajax()实现交互
$.ajax({
url : "/json/index",
type : "post",
async : true,
dataType : "json",
data : {
name:"xiaomi",
sex:'男'
},
success : function(result) {
console.log(result.name)
},
error : function(xhr) {
console.log("错误提示: " + xhr.status + " " + xhr.statusText);
}
});
本文链接:http://so.lmcjl.com/news/7283/