1、很纳闷,在post中alert的内容和在post外alert的内容不一样,然后我就把两个地方都alert出来,结果post外的内容先出来,post内的内容后出来,这时,我才想起来,$.post方法是异步的。
function EditRole(o)
{
var eid = $(o).parent("td").parent("tr").attr("eid");
var Vauthority = "";
var Vname = "";
var EditAuthorityUrl = "./ajax/user/role_info";
$.post(EditAuthorityUrl,{
id:eid
},function(d){
alert("Vauthority:"+d.authority);
alert("Vname:"+d.name);
Vauthority = d.authority;
Vname = d.name;
},'json');
alert("Vauthority:"+Vauthority);
alert("Vname:"+Vname);
}
2、正确的写法应为在function(d){}内部写完所有的操作