2

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

mXX
  • 3,595
  • 12
  • 44
  • 61
  • when you say you are using websockets, you have a websocket on the server? if that is the case, you wont retrieve ajax requests from that endpoint. you need to setup your client to handle sockets as well like socket.io – michael truong Apr 02 '14 at 00:14
  • No no I'm saying that I can't use websockets. I want to do it purely with JavaScript /JQuery /or an other js plugin. But I can't use websockets. – mXX Apr 02 '14 at 06:53
  • not many servers will get you back a successful response in 10 milliseconds – michael truong Apr 02 '14 at 17:19

0 Answers0