Skip to content

@scripting /wordnikFromJavaScript
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
<title>Wordnik demo from JavaScript</title>
<script src=""></script>
var baseUrl = "";
var apiKey = "a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5"; //demo key from
function getSynonyms (theWord, callback) {
var url = baseUrl + theWord + "/relatedWords?useCanonical=true&relationshipTypes=synonym&limitPerRelationshipType=100&api_key=" + apiKey;
var jxhr = $.ajax ({
url: url,
dataType: "text" ,
timeout: 30000
.success (function (data, status) {
var array = JSON.parse (data);
console.log (data);
callback (array [0].words)
.error (function (status) {
console.log ("getSynonyms: url == " + url + ", error == " + JSON.stringify (status, undefined, 4));
.divPage {
width: 50%;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
border: 1px solid silver;
background-color: whitesmoke;
padding-left: 15px;
<div class="divPage">
<p>This is a bit of sample code that accesses the <a href="">WordNik AP</a>I from JavaScript in the browser.</p>
<p>Here are the synonyms for "happy":</p>
<div id="idSynonymList"></div>
<p>For more info see this <a href="">blog post</a> on</p>
getSynonyms ("happy", function (words) {
var s = "";
for (var i = 0; i < words.length; i++) {
s += "<li>" + words [i] + "</li>"
$("#idSynonymList").html ("<ul>" + s + "</ul>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.