Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
如何确保调用jquery的回调_Jquery_User Interface - Fatal编程技术网

如何确保调用jquery的回调

如何确保调用jquery的回调,jquery,user-interface,Jquery,User Interface,如何确保正在调用回调代码 确保回调在到达检查gotMinPremium或gotMaxPremium之前到达 我不想使用setTimeOut函数 setTimeOut函数使脚本始终运行。还有别的方法吗 谢谢你你的设置超时调用不起作用,因为调用设置超时并不会阻止它执行后的所有操作,它只是注册一个代码块,在将来某个时候运行,然后立即执行设置超时后面的代码 使用延迟对象,您可以启动两个AJAX调用,并等待它们都完成后再继续: var getMin = $.post(...); var getMax =

如何确保正在调用回调代码

确保回调在到达检查gotMinPremium或gotMaxPremium之前到达

我不想使用setTimeOut函数

setTimeOut函数使脚本始终运行。还有别的方法吗


谢谢你

你的
设置超时
调用不起作用,因为调用
设置超时
并不会阻止它执行后的所有操作,它只是注册一个代码块,在将来某个时候运行,然后立即执行
设置超时
后面的代码

使用延迟对象,您可以启动两个AJAX调用,并等待它们都完成后再继续:

var getMin = $.post(...);
var getMax = $.post(...);

$.when(getMin, getMax).done(function(d1, d2) {
     // d1 and d2 will contain the result of the two AJAX calls
     MinPremium = d1.MinPremium;
     MaxPremium = d2.MaxPremium;

     ...
});
请注意,这将始终进行两个AJAX调用(并并行进行)。或者:

$.post(...).done(function(data) {
    minPremium = data.MinPremium;

    // handle your minimum test here
    ...

    $.post(...).done(function(data) {
        maxPremium = data.MaxPremium;

        // handle maximum test here
        ...
    });
});
FWIW,有什么原因不能让一个AJAX调用同时返回两个值吗