In addition to the async: false to synchronization, what method, can in the case of asynchronous,
fix this problem?
Var ABC="";
Url: url,
DataType: 'json,
Type: "post",
//async: false,
Success: the function (data) {
.
}
});
ABC=XXXXXX a series of operations
CodePudding user response:
1, will be in the subsequent operations on the success callback function, but and makes no difference to synchronous2, the definition of a logo, modify the logo in the success callback, subsequent judgment after successful to implement the logic behind the
3, will the back of the code with setTimeout
CodePudding user response:
After successful to perform follow-up operationsCodePudding user response:
Yes, agree with 1/f, define a logo, modify the logo in the success callback, subsequent judgment before performing the logic behind the success, even call or set the timeout, is to determine whether there is the return value, only to perform,CodePudding user response:
Don't want to change to synchronization, is, of course, and the result of the asynchronous operation related operations in the asynchronous get together after the operation,Of course you can also use async/awit for processing, can be on the business processes to achieve the result of "synchronization"
Async function getData () {
The return of new Promise ((resolve, reject)=& gt; {
$. Ajax ({
Url: url,
DataType: 'json,
Type: "post",
Success: the function (data) {
Resolve (data)
},
Error: function (err) {
//$. Ajax error: there are several values should be the default available, you can according to need to reject
Reject (err)
}
})
})
};
Async function fn () {
Try {
Let data=https://bbs.csdn.net/topics/await getData ();
console.log(data);
{} the catch (err)
console.log(err);
}
}
Fn ();
Finally: defined identifier is not recommended, the business logic is not clear, and unlikely to well so it can handle the goal, but abruptly with a timer to do class round robin
CodePudding user response:
On the first floor, the common treatment, see also commonly.CodePudding user response:
The processing of ABC=XXX wrote in the asynchronous method, such asSuch as ABC=await XXX
Then XXX with async calls ajax to get the data