Wednesday, 15 March 2017

trying to grab xml using XMLHttpRequest, readyState never turns into 4

i'm trying to grab xml from the url. I'm using nodejs for this. The code:

    var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;    
    var x = new XMLHttpRequest();
    x.open("GET", "https://cardo-ua.com/get_xmlprice.php", true);
    x.onreadystatechange = function () {
      if (x.readyState == 4 && x.status == 200)
      {
        var doc = x.responseXML;
        console.log(doc);
      } else {
        console.log("status:", x.status, "readyState:", x.readyState);
      }
    };
    x.send(null);

But it won't show xml. My output:

status: 0 readyState: 1
status: 0 readyState: 2
status: 200 readyState: 3

The last row is duplicated about 20-30 times and that's all. I've been waiting for about 5 mins to be sure that it's not still loading (xml is quite big).
Thanks for any advice.



via rocknow

No comments:

Post a Comment