$.ajaxSettings.async = false
;
//在执行之前加$.ajaxSettings.async = false; (同步执行)
1 function get_no_order_array() { 2 var order_info = show_order(); 3 var order = []; 4 $.ajaxSettings.async = false;//在执行之前加$.ajaxSettings.async = false; (同步执行) 5 $.getJSON("../JSON/customers.json", function (date) { //<span style="line-height: 1.5;">$.getJSON不懂的话可以看一下我之前的博客,或是专门学习一下 “JSON”</span> 6 date["man"].forEach(function (person) { 7 if (order_info.k_obj[person] == undefined) { 8 order.push(person); 9 } 10 }) 11 }); 12 $.ajaxSettings.async = true;//执行你的代码之后及时恢复为$.ajaxSettings.async = true; (异步执行) 13 return order; 14 }