Skip to content

Instantly share code, notes, and snippets.

@base698
Last active December 18, 2015 03:08
Show Gist options
  • Save base698/5715612 to your computer and use it in GitHub Desktop.
Save base698/5715612 to your computer and use it in GitHub Desktop.
Something like this....
<html>
<meta charset="utf-8">
<head>
<SCRIPT LANGUAGE="JavaScript">
function textProcess(form) {
var apiCalls= [];
var textInput = form.inputbox.value;
var inputArray=textInput.split(" ");
for (i=0; i<inputArray.length; i++){
var t_url = "http://api.wordnik.com/v4/word.json/" + inputArray[i] + "/relatedWords?useCanonical=true&relationshipTypes=synonym&limitPerRelationshipType=20&api_key=13ee2e8b568303c9950050dad6205899a9cf91816cad42252";
apiCalls.push(t_url);
}
console.log (apiCalls);
for (i=0; i<apiCalls.length; i++){
(function(apiCall) {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", apiCall, true);
xmlHttp.send( null );
xmlHttp.onload = function() {
var wordnikResponse = xmlHttp.responseText;
console.log(wordnikResponse);
console.log(wordnikResponse[0].words);
var parsedResponse = JSON.parse(wordnikResponse);
console.log(parsedResponse);
console.log(parsedResponse.words);
};
})(apiCalls[i]);
}
}
</script>
</head>
<body>
<div id= "Input Form">
<FORM NAME="input" ACTION="" METHOD="GET">
<INPUT TYPE="text" NAME="inputbox" rows = "10" placeholder="input" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="textProcess(this.form)">
</FORM>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment