我有user_permissions
变量,我定义了它以供全局使用,在 post 方法上设置它之后,我没有打印问题,但是在下面的多行中使用这个变量后,我得到了null
结果???
jQuery(最少的代码):
var user_permissions = null;
$(document).ready(function(e) {
$.post('model/controller.php' ,{ username:iId_username , postaction:'getUserPermission' },
function(data){
user_permissions=0;
user_permissions = data.user_permissions;
console.log(user_permissions); // RESULT is : {"user_permissions":"8"}
},'json');
$.each(listPermissions, function(i, item) {
if ( user_permissions == listPermissions[i].id ) selected = "selected='selected'"; else selected = '';
console.log(user_permissions); // RESULT is : null
selectElement += "<option value='" + listPermissions[i].id + "' "+ selected + ">" + listPermissions[i].permission_title + "</option>";
});
});
我的代码问题是什么?