weixin_33708432 2017-06-27 10:17 采纳率: 0%
浏览 18

$ .when的jQuery问题

I'm using a call back function which will check for 60secs. If file avaible then will return true else will return false. The call back function I'm calling after ajax call.. Here is code below :

$.ajax({
    type: '..',
    url: '..',
    data: '..',
    success: function(data) {
        window.loadFile(data);
    }
})

window.loadFile = function(filePath) { // I'm getting the data. Now passing to call back function
    $.when(window.waitTillFileExistsAndLoad(filePath)).done(function(data) {
        alert(data) // here data is giving me undefined.. 
    });
}

var timer = 0;
window.waitTillFileExistsAndLoad = function(fileName) {

    var checkFile;

    return $.get(fileName, function(data) { // If file found.. 

        timer = 0;
        return true;

    }).error(function() { // If file not found.. 

        timer += 1; 

        if(timer == 30) {

            timer = 0;
            clearTimeout(checkFile);
            return false;

        } else {

            console.log('error occured');
            checkFile = setTimeout(function() {
                window.waitTillFileExistsAndLoad(fileName);
            }, 2000);

        }

    });
}

The issue is that when I'm using $.when() it's giving me undefined. Please suggest me what's wrong in my code.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测