这应该返回一个包含图片文件名列表的JSON对象.注释警报显示正确的数据,但alert(getPicsInFolder("testfolder"));显示"error".
function getPicsInFolder(folder) {
return_data = "error";
$.get("getpics.php?folder=" + folder, function (data) {
data = jQuery.parseJSON(data);
$.each(data, function (index, value) {
data[index] = "folders/" + folder + "/" + value;
});
//alert(data); // This alert shows the correct data, but that's hardly helpful
return_data = data;
});
return return_data;
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我如何在函数中使用$ .post()强制回调邮件回调?
例:
function myFunction(){
$.post(postURL,mydata,function(data){
return data;
});
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用.done()和.queue()来玩它但是它们都没有用.我明白我的例子有一个根本的缺陷; 话虽如此,我怎样才能实现我想要的功能?