PDA

View Full Version : XMLHttpRequest Problem



icu222much
29 Oct 2011, 01:58 PM
I'm trying to create a script that will call a flickr rest method and output its XML. I have written the following code, but it seems to not work. I am stumped, and was wondering what I am doing wrong.

I have uploaded my code to http://www.sfu.ca/~jca41/stuph/blahh/example.html



function foo() {
//var url = "http://flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=aa9b622e629e51d3fcda1f967c429237&photo_id=6174355034";
alert(loadXMLDoc(url));
}

function loadXMLDoc(dname) {
if (window.XMLHttpRequest) {
xhttp=new XMLHttpRequest();
} else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseText;
}
</script>

hyperion
02 Nov 2011, 01:01 AM
XMLHttpRequest won't let you access resources on other domains than your. In order for this to work, you need a php script that fetches flickr url and XMLHttpRequest will request the file on your domain.

flickr.php


echo file_get_content('http://flickr.com/services/.....');


flickr.html


var url = "flickr.php";