i having worker has array of urls. loop through these urls , throw ajax call, inside success method of ajax when send message website, sends last request.
app.js
var worker = new worker('worker.js'); var urls = ['url1','url2','url3']; worker.addeventlistener('message', function(e) { console.log('worker: ', e.data.url); }, false); worker.postmessage({"args":[urls]});
worker.js
self.addeventlistener('message', function(e) { function load(url){ var xmlhttp=new xmlhttprequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { console.log(xmlhttp); self.postmessage({'url':url}); } } xmlhttp.open("get",url,true); xmlhttp.send(); } var urls = e.data.args[0]; for(var = 0; i<urls.length; i++){ load(urls[i]); } }, false);
now inside console.log();
of app.js, output of last url.
i don't all urls response.
can ?
the answer real easy. make line 3
var xmlhttp=new xmlhttprequest();
what you're doing now, setting xmlhttp global variable. means overriding variable every time line 3 executed.
Comments
Post a Comment