I am encountering an issue with the setTimeOut method that calls a function and sets a delay. The function should be called repeatedly after each request is completed, but it only runs once. It works fine without using backbone.js, but I am not sure why it doesn't work after integration with backbone.js. Any assistance would be greatly appreciated!
Here is a function in the client that sends a GET request to the server to retrieve data. The request runs at a time interval determined by the server. When new data arrives, the client fetches it and the request restarts.
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;
}