bing search api ajax does not work
        Posted  
        
            by jhon
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jhon
        
        
        
        Published on 2010-05-30T05:45:08Z
        Indexed on 
            2010/05/30
            5:52 UTC
        
        
        Read the original article
        Hit count: 372
        
Hi guys,
I want to use the Bing's search api with javascript. Actually, I want the user to write something and query Bing in order to get just images.
so, I tried it using ajax. If I try the url http://api.search.live.net/xml.aspx?Appid=[YOURAPIKEY]&sources=image&query=home directly (with the browser) I do get an xml document.
but if I use XMLHttpRequest it does not work.
<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( xhr.readyState +" "+xhr.status +xhr.statusText +xhr);
};
xhr.send(null);
</script> 
</body>
</html>
Questions: 1) why does the code from above does not work? 2) any other way to do this without XMLHttpRequest?
thanks.
btw. I'm just interested in fix this for Firefox and without external libraries (jquery and so on).
© Stack Overflow or respective owner