I'm doing an Ajax call to a Web service that's pushing a JSON object every ~200ms. I'm trying to retrieve the data, but it isn't really going well. As the webservice page is never 'loaded' it's always 'running' so the Ajax call never retrieves something.
After the poll of 10ms it gets aborted and the error I'm getting is a timeout
The thing is I'm trying to achieve is that if the url has a new JSON object, that I display it directly on my page.
The code
(function poll(){
$.ajax({
url: myURL
success: function(data){
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown){
console.log("\n jqXHR " + jqXHR);
console.log("\n textStatus " + textStatus);
console.log("\n errorThrown " + errorThrown);
},
dataType: "json",
complete: poll,
timeout: 10
});
})();
});
The url provides every ~200ms JSON objects like this (key value pair changes to dummy data of course) :
{'id':'1','name':'john','age':'7'} {'id':'2','name':'john','age':'7'}{'id':'3','name':'john','age':'78'}
Can someone help me with this? Is what I'm trying to achieve possible with Ajax? If not, why not? Any alternatives? I can't use websockets