2

I was trying to read an XML data provided by the url

URL: http://api.123rf.com/rest/?method=123rf.images.search&apikey=0c29eba8ae174db26c5946b2f4e7b3c4&keyword=dance&orderby=most_downloaded&perpage=20&media_type=all

but I not able to get a responce back using the following code:

var xhr;
if (window.XMLHttpRequest) xhr = new XMLHttpRequest();      // all browsers except IE
else xhr = new ActiveXObject("Microsoft.XMLHTTP");      // for IE

xhr.open('GET', 'http://api.123rf.com/rest/?method=123rf.images.search&apikey=0c29eba8ae174db26c5946b2f4e7b3c4&keyword=dance&orderby=most_downloaded&perpage=20&media_type=all', false);
xhr.onreadystatechange = function () {
    if (xhr.readyState===4 && xhr.status===200) {           
        var items = xhr.responseXML.getElementsByTagName('image');
        var output = '<ul>';
        for (var i=0; i<items.length; i++) output += '<li>' + items[i].id + '</li>';
        output += '</ul>';

        var div = document.getElementById('update');
        div.innerHTML = output;
    }
}
xhr.send();

I am able to view the data if I download the xml file and upload it directly to my host. Is there a way to view the data from an external url and displaying it using Javascript?

Thanks.

MPummel
  • 55
  • 4
  • When you say, you can download the xml file but the request ajax request doesn't work, it sounds like some problems with your server/setup/request-header-data or the api server is rejecting your request. This could be some settings on the api server you can't affect. – michelgotta Nov 22 '16 at 23:07
  • 1
    Please look here : http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource – Mihai Alexandru-Ionut Nov 22 '16 at 23:08

0 Answers0