這是一個Promise的基本寫法。
new Promise((resolve, reject)=> {
resolve()
})
想要函數同步進行 需要以下寫法。
var ss = '';
function ajaxs() {
return new Promise(function(resolve, reject) {
resolve(
$.ajax({
type: "get",
url: "http://192.168.1.78:8000/api/Pick?productionLine=NW出口線" ,
dataType: 'json',
success: function(res) {
ss = res;
}
})
)
})
}
function ajaxss(ss) {
return new Promise(function(resolve, reject) {
resolve(
console.log(ss)
)
})
}
async function hh() {
console.time("doIt");
await ajaxs();
await ajaxss(ss);
console.timeEnd("doIt");
};
hh();