I'm using a thesaurus API,
http://thesaurus.altervista.org
to get synonyms to print to the page. In this demo version,
http://plnkr.co/edit/6pNYlXcgiwxHz00AY5CT?p=preview
it works when you type 'peace', otherwise, in console, if we follow the link, we see a GET error:
{"error":"the key test_only is restricted, please use your own key!"}
(EDIT: to clarify: Demo mode is not the issue. I want to make an alert.) For errors, I want the browser to alert "Oops, word not found. Please choose another word."
Here is the js code from the demo:
//function activated on user input
function myFunc(){
var userInput = document.getElementById('userInput');
var result = userInput.value;
var s = document.createElement("script");
//This demo works with the keyword 'peace' only. So searching for e.g. 'hat' will cause an error.
s.src = "http://thesaurus.altervista.org/service.php?word=" + result + "&language=en_US&output=json&key=test_only&callback=process"; // NOTE: replace test_only with your own KEY
document.getElementsByTagName("head")[0].appendChild(s);
window.process = function (result) {
//my attempt at throwing an error
if(result.error){alert("Oops, word not found. Please choose another word.");}
//normal processing..
output = "";
for (key in result.response) {
list = result.response[key].list;
output += list.synonyms+"<br>";
}
if (output)
document.getElementById("synonyms").innerHTML = output;
}
}
I did some research and found this answer (it's jQuery but mine's not but it might be relevant?):
https://stackoverflow.com/a/2568788
Any help much appreciated, thanks.