javascript - XHR State Error when readyState is as expected -
i writing javascript program requires significant usage of xhr methods. using asynchronous style. core of have.
global = {}; global.xhr = {}; global.xhr.requestqueue = []; global.xhr.responsequeue = []; xhr = new xmlhttprequest(); xhr.first = true; xhr.onreadystatechange = function() { //console.log(this.readystate); if(this.readystate == 4) { if(this.first) { this.first = false; global.carouselitems = parseint(this.responsetext); global.onslidecountreceived(); } else { global.xhr.responsequeue.push({status: xhr.status, responsetext: xhr.responsetext}); if(global.xhr.requestqueue.length > 0) { xhr.open("get", global.xhr.requestqueue[0]); global.xhr.requestqueue.shift(); } } } if(xhr.readystate == 1) { xhr.send(); } } //code adds bunch of items global.xhr.requestqueue xhr.open("get","assets/carousel/items.php");
but when run this, chrome dev console prints bunch of errors following.
uncaught invalidstateerror: failed execute 'send' on 'xmlhttprequest': object's state must opened.
this despite call xhr.send()
being in snippet above, wrapped in if
statement. confusing me, because way see suggests make call xhr.send()
when xhr.readystate
1
, equivalent xmlhttprequest.opened
, yet complaint not being case.
by way, requests complete successfully, , global.xhr.responsequeue
populated expected response info. these intra-domain requests.
Comments
Post a Comment