Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8096797

XHR to a CORS-enabled site seems to fail

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 9
    • 7u45
    • deploy
    • linux 64 bit, jdk 1.7u51

      The following page:
      http://datao.zerezo.com/tot.html
      fills itself with an XHR call to a CORS-enabled website (http://dbpedia.org/sparql).

      That process works fine in (for example) Chrome.

      But I get an error when I load this page in a WebView.
      It seems the status of the XHR's response is 0, instead of 200 in Chrome.

      Did I do something wrong?

      PS: the source code for the webpage is:

      <html>
      <head>
      <title>Simple Ajax Example</title>
      <script language="Javascript">
      var urlToReach = 'http://dbpedia.org/sparql&#39;;
      function xmlhttpPost() {
          var xmlHttpReq = false;
          var self = this;
          // Mozilla/Safari
          if (window.XMLHttpRequest) {
              self.xmlHttpReq = new XMLHttpRequest();
          }
          // IE
          else if (window.ActiveXObject) {
              self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
          }
          self.xmlHttpReq.open('GET', urlToReach, true);
          self.xmlHttpReq.onreadystatechange = function() {
              if (self.xmlHttpReq.readyState == 4) {
                  if(self.xmlHttpReq.status == 200)
                  updatepage(self.xmlHttpReq.responseText);
                  else
                  updatepage('self.xmlHttpReq.status is '+self.xmlHttpReq.status+', sorry. Unable to get data back from '+urlToReach);
              }
          }
          self.xmlHttpReq.send();
      }

      function updatepage(str){
          document.getElementById("result").innerHTML = str;
      }
      </script>
      </head>
      <body onload="xmlhttpPost()">
        <div id="result">the result will appear here</div>
      </form>
      </body>
      </html>

            cbensen Chris Bensen (Inactive)
            orosseljfx Olivier Rossel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: