Skip to content

Instantly share code, notes, and snippets.

@srkirkland
Created February 24, 2010 23:33
Show Gist options
  • Save srkirkland/314026 to your computer and use it in GitHub Desktop.
Save srkirkland/314026 to your computer and use it in GitHub Desktop.
Bing Spelling API Example
<script type="text/javascript">
$(function() {
$("#checkSpelling").click(function(event) {
var text = $("#query").val();
var encodedText = escape(text);
var spellService = "http://api.bing.net/json.aspx?AppId=APIKey&Query=" + encodedText + "&Sources=Spell&Version=2.0&Market=en-us&Options=EnableHighlighting&JsonType=callback&JsonCallback=SearchCompleted";
$.getScript(spellService);
event.preventDefault();
});
});
function SearchCompleted(result) {
console.dir(result);
var spellSuggestions = result.SearchResponse.Spell;
if (spellSuggestions.Total != 0) {
var firstSuggestion = spellSuggestions.Results[0].Value;
$("#suggestion").text("Did you mean: " + firstSuggestion + " ?");
}
}
</script>
<h2>Spelling Test</h2>
<p>
Spell Something: <input type="text" id="query" value="mispelling pythn" /> <a href="#" id="checkSpelling">Check</a>
</p>
<p>
<span id="suggestion"></span>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment