1、使用$.ajax([options])
$.ajax({
type: "post",//请求类型
url: "", //请求的URL
charset: "utf-8",
dataType: "json",//数据类型
data: {}, //要发送的数据
//成功回调函数
success: function (data) {//请求成功,data是前端发送来的数据也是json格式
console.log(data);
},
//错误回调函数
error: function () {//失败
console.log("error");
}
});
2、使用$.post(url,[data],[callback],[type])
url:请求地址
data:要发送的数据
callback:回调函数
type:请求方式,一般省略
$.post(
"url",
{},//发送至服务器的 key/value 数据,一般是json数据
function (data) {//回调函数,自动将后端发送来的数据赋值给data
}
);
3、使用$.get(url,[data],[callback],[type])
用法同2