我对调用函数 self 并设置延迟的方法 setTimeOut 有问题,应该在每个请求完成后一次又一次地调用该函数,但它只运行一次。它在不使用backbone.js 的情况下工作,不知道它在与backbone.js 集成后不起作用。任何帮助表示赞赏!
所以这是客户端中的一个函数,它运行 GET 请求从服务器获取数据,请求按时间间隔运行(由服务器决定),一旦数据进入,客户端获取它,然后请求再次运行。
    getRequest:function() {
        var XHR = $.ajax({
            url: '/nextdocument',
            type: 'GET',
            async: true,
            cache: false,
            timeout: 11000, 
            success:function(data) {
                var name = data.description;
                var price = data.price;
                console.log("read--> " + name + price);
                setTimeout("this.getRequest", 1000);
                if (data.ok == "true") {
                    data["ok"] = data.ok;
                    $.ajax(
                        {
                            url: "/customerdone",
                            data: JSON.stringify(data),
                            processData: false,
                            type: 'POST',
                            contentType: 'application/json'
                        }
                    )
                }else{
                    //no document if no read in
                    console.log("error--> " + data.errorMessage)
                }
            }
        })
        return XHR;
    }