0

I have the following code that gets "XMLHttpRequest cannot load due to access control checks." error:

var xhr = new XMLHttpRequest();
        xhr.withCredentials = false;
        xhr.onreadystatechange = function() {
            if (xhr.readyState == XMLHttpRequest.DONE) {
              alert(xhr.responseText);}}
        xhr.open('GET', 'http://gd.geobytes.com/GetCityDetails?callback=?', true);
        xhr.send(null);

But if I use jquery as follows, it works:

$.getJSON('http://gd.geobytes.com/GetCityDetails?callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
        alert(JSON.stringify(data, null, 2));});

Is there a way to use XMLHttpRequest instead of Jquery to get the same result? From previous questions 1, 2, 3, 4, 5(the same question but not answered), 6, 7, 8, what I found is that using XMLHttpRequest we cannot do it? as the questions are very old, I would like to know if this is true?

Alex
  • 1,914
  • 6
  • 26
  • 47

0 Answers0