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