如何在同一功能中訪問「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