Looking to incorporate Bing's search API using JavaScript. My goal is to allow the user to input a query and retrieve only images from Bing.
I attempted to use Ajax for this task. When entering the URL directly in the browser, I successfully retrieved an XML document.
However, I encountered issues when using XMLHttpRequest.
<html>
<body>
<script>
var xhr = new XMLHttpRequest();
var url="http://api.search.live.net/xml.aspx?Appid=[YOURAPIKEY]&sources=image&query=home"
xhr.open("GET", url, true );
xhr.onreadystatechange=function(){
/*if( xhr.readyState == 4 && xhr.status == 200) {
document.write( xhr.responseText );
}*/
alert( "state: "+xhr.readyState +" status: "+xhr.status +" statusText: "+xhr.statusText +" respText: "+xhr.responseText);
};
xhr.send(null);
</script>
</body>
</html>
Questions: 1) Any insights on why the previous code snippet doesn't function as expected? 2) Are there alternative methods to achieve this without using XMLHttpRequest?
Thank you in advance.
By the way, my focus is on resolving this issue specifically for Firefox and without relying on external libraries like jQuery.