Javascript-форум (https://javascript.ru/forum/)
-   Internet Explorer (https://javascript.ru/forum/css-html-internet-explorer/)
-   -   Не приходит json объект ie9 (https://javascript.ru/forum/css-html-internet-explorer/69636-ne-prikhodit-json-obekt-ie9.html)

Fierfoxik 07.07.2017 17:56

Не приходит json объект ie9
 
Долго мучался и пыжился с xhr в ie9.
Полифилы и костыли в итоге все сошлось к XDomainRequest

Проблема в том что по какой то магической причине

этот код отлично работает

function createCORSRequest(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {
    // XHR for Chrome/Firefox/Opera/Safari.
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
    // XDomainRequest for IE.
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    // CORS not supported.
    xhr = null;
  }
  return xhr;
}

// Helper method to parse the title tag from the response.
function getTitle(text) {
  return text.match('<title>(.*)?</title>')[1];
}

// Make the actual CORS request.
function makeCorsRequest() {
  // This is a sample server that supports CORS.
  var url = 'http://html5rocks-cors.s3-website-us-east-1.amazonaws.com/index.html';

  var xhr = createCORSRequest('GET', url);
  if (!xhr) {
    alert('CORS not supported');
    return;
  }

  // Response handlers.
  xhr.onload = function() {
    var text = xhr.responseText;
    var title = getTitle(text);
    alert('Response from CORS request to ' + url + ': ' + text);
  };

  xhr.onerror = function() {
    alert('Woops, there was an error making the request.');
  };

  xhr.send();
}



Но как только я начинаю передавать json из папки на сервере json файл, он не в какую не хочет принимать его.
responseText пуст, алерт срабатывает


Часовой пояс GMT +3, время: 08:10.