Ajax请求语法
$.get和$.post都是异步请求,如果同步就用$.ajax
$.ajax请求
$.ajax({
async:false, //使用同步Ajax请求
type: "POST",
url:"demo.php",
data: {"name":name,"age":24},
dataType:"json", //省略智能判断类型
success: function(msg){
//请求成功后的函数
}
error:function(msg){
//请求失败后的函数
}
});
$.get请求:
$.get("demo.php", {"data":data},function(msg){ //成功后函数 },"json");
$.post请求
$.post("demo.php", {"data":data},function(msg){ //成功后函数 }, "json");