I'm using an Thesaurus API. The website says: The list of synonyms related to a word can be retrieved by sending a HTTP GET message to the endpoint but a tab of the site finds a synonym with the following code:
var s = document.createElement("script");
s.src = "http://thesaurus.altervista.org/service.php?word=peace&language=en_US&output=json&key=test_only&callback=process";
document.getElementsByTagName("head")[0].appendChild(s);
It then defines the callback function 'process' that is part of the url above and process is passed a "result" parameter with the result. I'm unused to making an HTTP GET request in this manner and simply curious about it. I've only ever seen requests made using XMLHttpRequest. (New to programming).
My main question is whether you could get the same result with XMLHttpRequest, something like the following. When I try it doesn't work. Any information about how the above code is making an HTTP request would be much appreciated too.
var req = new XMLHttpRequest();
req.addEventListener("load", reqListener});
req.open("GET", url, true); //where url is same as above but without callback part
req.send();
function reqListener() {
alert(req.statusCode);
}