Let's talk about the problems I've been having. One of my previous functions wanted to call the return value of the previous function, but its return value was always empty, and then I turned over some data to understand that the asynchronous request was at mischief, not to mention, look at the example, this is the code for the return value function I had before:
function Get_no_order_array () {
var order_info = Show_order ();
var order = [];
$.getjson (".. /json/customers.json ", function (date) {
date[' man '].foreach (function (person) {
if (Order_info.k_obj[person ] = = = undefined) {
order.push (person);}})
;
return order;
}
It was later found that the printed array order was empty, following the corrected code:
function Get_no_order_array () {
var order_info = Show_order ();
var order = [];
$.ajaxsettings.async = false;//plus $.ajaxsettings.async = false before execution; (Synchronous execution)
$.getjson (".. /json/customers.json ", function (date) {//<span style=" line-height:1.5; " >$.getjson don't understand, you can look at my previous blog, or learn about "JSON" </span>
date[' man '].foreach (function (person) {
if (order_info.k_obj[person] = = undefined) {
order.push (person);
}
})
});
$.ajaxsettings.async = true;//The execution of your code in time to revert to $.ajaxsettings.async = true; (asynchronous execution) return order
;
}
Add a $.ajaxsettings.async = False before the loop; Represents a synchronous execution, so that he executes it in sequence.
Simultaneous execution of multiple $.getjson () data confusing problem resolution
Add $.ajaxsettings.async = False before execution; (Synchronous execution)
Return to $.ajaxsettings.async = true in time after executing your code (asynchronous execution)
Otherwise, the code that needs to be executed asynchronously elsewhere.
Example
$.ajaxsettings.async = false;
$.getjson (URL, data, function (data) {});
$.getjson (URL, data, function (data) {});
$.getjson (URL, data, function (data) {});
......
$.ajaxsettings.async = true;
The above analysis of the $.getjson asynchronous request and synchronization request is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.