1.
$.ajaxSetup({ async : false //设置ajax为同步方式,异步方式的话在赋值时数据还未提取出来 });var t = ""; var engineerMethod = $("#engineerMethod").val(); $.post("/civilizationconstruction/template!vali.action",{"templateUnit.engineerMethod":engineerMethod},function(data){ t = data;//赋值给全局变量 });
2.
var t = "";$.ajax({ async:false, //使用同步请求,因为异步请求不能将返回值传给全局变量; type: "POST", url: "server.php", data: "", success: function(msg){ t=msg; } });
时间: 2024-10-29 19:11:49