0

Having a weird issue with onprogress for my XMLHttprequest.

I'm using the following code to log the response onprogress:

xhr.addEventListener("progress", function(event) {
      target = (event.currentTarget) ? event.currentTarget : event.srcElement;
      console.log('response: ',target.response);
}, false);

If i console.log just target, I get an object, where I can see that response has text like so:

enter image description here

But if I try and log target.response or target.responseText, it is completely empty. No errors or even a length on the string.

Pretty sure it has something to do with the response being JSON, but I'm not sure where to start. Any ideas?

wesbos
  • 25,839
  • 30
  • 106
  • 143
  • Maybe `progress` is only triggered *during* the XMLHTTPRequest, not at the end when the response was received? There are known problems when logging objects in Chrome: http://stackoverflow.com/q/4057440/218196. MDN says about `readyState 3`: *"Downloading; responseText holds partial data."*. – Felix Kling Nov 25 '13 at 16:52
  • You should get multiple progress events with growing response strings (and it can be empty at the first time). If you log the whole request object, you will only see the response that has already fully arrived. – Bergi Nov 25 '13 at 16:53
  • I have two responses and I've put a 10 second sleep inbetween them. So this isn't the issue. – wesbos Nov 25 '13 at 16:59

0 Answers0