Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 18, 2013 07:41
Show Gist options
  • Select an option

  • Save thinkphp/5185631 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/5185631 to your computer and use it in GitHub Desktop.
A client JavaScript for Microsoft's Bing Search API REST.
var bing = Bing( {appid: 'your-api-key'} );
bing.search(q.value, function( data ){
var res = data.SearchResponse.Web.Results;
if(res && res.length > 0) {
var all = res.length,
out = '<h2>Results</h2><ol>';
for(var i = 0;i < all; i++) {
out += '<li><h3><a href="'+res[i].Url+'">'+res[i].Title+'</a></h3><p>'+res[i].Description+'<span>'+res[i].DisplayUrl+'</span></p></li>';
}
out += '</ol>';
b.innerHTML = out;
} else {
b.innerHTML = '<h2>Bing</h2><ul><li><h3>No results found. </h3></li></ul>';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment