3

This request only work with internet explorer, I've tried many different solutions, for two days I've been trying to make it work and I couldn't . please advise.

pure javascript:

     var xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            data = xmlhttp.responseText;
            console.log(data);
            document.getElementById("p").innerText = data;
         }
       };
    xmlhttp.open("GET", "http://myanimelist.net/api/anime/search.xml?q=naruto", true);
    xmlhttp.setRequestHeader('Authorization','Basic TUFMUTpNTU1xcXExMTEyMjJAQEAjIyM='); 
    xmlhttp.send(null);

jquery:

    $.ajax({
   url: "http://myanimelist.net/api/anime/search.xml?q=naruto",
   cache: false,
   headers: {"Authorization": "Basic TUFMUTpNTU1xcXExMTEyMjJAQEAjIyM=" ,"Content-Type": "application/xml"},
   method: 'GET',
   dataType: 'xml',
   async: true,
   success: function(data) {
     var xmlText = new XMLSerializer().serializeToString(data);
     var xmlTextNode = document.createTextNode(xmlText);
     var parentDiv = document.getElementById('sdiv');
     parentDiv.appendChild(xmlTextNode);
    }
  });
MALQ
  • 31
  • 2

1 Answers1

0

AJAX is limited to the same domain of your site, because of the Same Origin Policy.

You will have to find a way to circumvent it or use AJAX in combination with server-side scripting to get the desired results. If you're going to use something like PHP, you could use something like simplexml_load_string(file_get_contents("http://example.org/search.xml?query")); but I think you'll also find that the domain in question is using HTTP authentication as well

Jonathan
  • 10,936
  • 8
  • 64
  • 79