Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created November 2, 2011 02:41
Show Gist options
  • Save jdjkelly/1332714 to your computer and use it in GitHub Desktop.
Save jdjkelly/1332714 to your computer and use it in GitHub Desktop.
Bing Spelling in JSON
var AppId = "D8E9ED76519B0D51D42D53256188D00E3A7BB2C2";
var requestStr = "http://api.bing.net/json.aspx?"
// Common request fields (required)
+ "AppId=" + AppId
+ "&Query=<?php the_search_query();?>"
+ "&Sources=Spell"
// Common request fields (optional)
+ "&Version=2.0"
+ "&Market=en-us"
+ "&Options=EnableHighlighting"
// JSON-specific request fields (optional)
+ "&JsonType=callback"
+ "&JsonCallback=?";
$(document).ready(function () {
$.getJSON(requestStr, function (data) {
console.log(data);
var spellingResponse = data.SearchResponse.Spell.Results[0].Value;
$('.category h3').append(' <span class="search-results">Did you mean <a href="http://varsity.kmsm.ca/?s=' + spellingResponse + '">' + spellingResponse + '</a>?</span>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment