Created
March 18, 2013 07:41
-
-
Save thinkphp/5185631 to your computer and use it in GitHub Desktop.
A client JavaScript for Microsoft's Bing Search API REST.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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