如何在同一功能中访问“mentorslist”varibale。 “mentorslist”是ajax调用的成功。但是我无法在mentors()函数中访问它。Ajax成功功能无法在自定义功能中访问
function mentors(){
var mentorslist = '';
$.ajax({
type: "POST",
url: <?php echo '"'.base_url().'index.php/MentorList/'.'"'; ?>,
data: { pagelimit: 1,json: "true" },
success: function(msg)
{
var obj = jQuery.parseJSON(msg);
var $mentor_list ="";
var mlist = '';
jQuery.each(obj.resset, function(i, val){
mlist = mlist+'<option value="'+val.mentor_Id+'">'+val.Name+'</option>';
$("#mlist").get(0).options[$("#mlist").get(0).options.length] = new Option(val.Name,val.mentor_Id);
});
mentorslist = mlist; //Able to access here
}
});
return mentorslist; // gives undefine error
}
请看这里mentorslist变量设置成ajax成功并试图通过自定义函数返回它,但它返回给我undefined。
mentorslist using done给undefined – Ni3
它的工作亲爱的...你是摇滚..非常感谢你。 – Ni3