方案一、
//在全局或某個需要的函數內設置Ajax異步為false,也就是同步.$.ajaxSetup({async : false});//然后再進行你的Ajax操作
$.post(地址, 參數, function(data, status) { if (status == "success") { //賦值給全局變量 } });
方案二、
$.ajax({type : "post",url :地址,data : "參數" + 參數的值,async : false,success : function(data){ //賦值給全局變量;}});