Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取jQuery get().done()函数的返回值_Javascript_Jquery - Fatal编程技术网

Javascript 获取jQuery get().done()函数的返回值

Javascript 获取jQuery get().done()函数的返回值,javascript,jquery,Javascript,Jquery,我有密码: function images(){ $.get("page").done(function(data) { manipulation to get required data }); } 我尝试从get函数内部获取变量,使用全局变量、返回值和函数外部的函数。有人知道如果调用images(),如何从get函数内部获取变量并将其作为值返回吗?您不能这样做,因为$.get()是异步执行的。解决方案是在图像中使用回调来处理$.get()返回的值 然后 更多

我有密码:

function images(){
    $.get("page").done(function(data) {
        manipulation to get required data
    });
}

我尝试从get函数内部获取变量,使用全局变量、返回值和函数外部的函数。有人知道如果调用
images()
,如何从get函数内部获取变量并将其作为值返回吗?

您不能这样做,因为
$.get()
是异步执行的。解决方案是在图像中使用回调来处理$.get()返回的值

然后


更多信息:

您不能这样做,因为
$.get()
是异步执行的。解决方案是在图像中使用回调来处理$.get()返回的值

然后


更多信息:

您有什么样的例子我可以使用吗?您有什么样的例子我可以使用吗?
function images(callback){
    $.get("page").done(function(data) {
        manipulation to get required data
        var d = ? //manipulated data that was supposed to be returned
        callback(d);
    });
}
//calls images
images(function(data){
    //this method will get called when the $.get() is completed, and data will be the value passed to callback(?) in the done function
})