hi after searching in the net about how to use the long polling in JavaScript I ended up with three ways, they are mentioned here briefly,but they are implemented using JQuery. I am confused which one to use in case that the AJAX request that I send to the server is asynchronous GET request ,and I don't know how many time it could take.
here is an example AJAX request:
function asynchGETRequest(method,url){ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log("ok"); } }; xhttp.open(method, url, true); xhttp.send(); return (xhttp.responseText); } var clientFunctions={ getAnswers : function(callback){ var res=asynchGETRequest("GET", "http://localhost:9000/answers"); callback(JSON.stringify(res)); } } clientFunctions.getAnswers (function(){ //do some code here after the ajax request is ended }); can some one guide me please?