1.自定義一個方法嗡综,如:Ajax,此處我傳了2個參數(shù)
var Ajax = function (options, url) {
return new Promise(function (resolve, reject) {
$.ajax({
type: "post",
data: options,
url: url,
success: function (res) {
resolve(res);
}
})
})
};
2.在使用的時候
Ajax(options,url).then(function(value){
// value 是后臺返回的數(shù)據(jù)尸曼,then 表示接口返回成功
console.log(value)
//return 是返回 連續(xù)的第二個 接口
return Ajax(options,url);//接口2
}).then(function(value){
//此處的value為 上面接口2返回的數(shù)據(jù)
})