jQuery Wrapper For Bing Web Search API - bingSearch.js

File Size: 4.27 KB
Views Total: 1626
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Wrapper For Bing Web Search API - bingSearch.js

jQuery bingSearch.js is a JQuery wrapper around the Bing Web Search API, that allows you to embed a Bing search into your webpage.

How to use it:

1. Add both jQuery JavaScript library and the jQuery bingSearch.js script to the webpage.

<script src="//code.jquery.com/jquery.min.js"></script>
<script src="bingSearch.js"></script>

2. Create a search field as follow:

<input type="text" class="keyword" placeholder="Search">
<button class="find">Search</button>

3. Create a container to display the search results.

<div class="result"></div>

4. Enable the search field to search anything using the Bing Web Search API.

$('.find').click(function() {
  $.bingSearch({
    apiKey: 'YOUR API HERE',
    keyword: $('.keyword').val(),
    onSuccess: function(response) {
      var data = response.webPages.value;
      $('.result').html('');
      for (var i = 0; i < data.length; i++) {
        let situs = data[i];
        let element = `
          <div class="siteList">
          <a href="${situs.url}" target="_blank">${situs.name}</a> <br/>
          <span class="displayUrl">${situs.displayUrl}</span> <br/> 
          ${situs.snippet}
          </div>
        `;
        $('.result').append(element);
      }
    }
  });
});

This awesome jQuery plugin is developed by arryanggaputra. For more Advanced Usages, please check the demo page or visit the official website.