The HTTP request to get synonyms can be implemented in Javascript using different solutions:
  • Plain javascript request
  • jQuery based request
Plain Javascript

The Javascript example requires support for JSON in browser, e.g. Firefox 3.5 can handle JSON. The example is quite simple, it invokes the thesaurus API with callback=process:

var s = document.createElement("script");
s.src = ""; // NOTE: replace test_only with your own KEY

function process(result) {
  output = "";
  for (key in result.response) {
    list = result.response[key].list;
    output += list.synonyms+"<br>";
  if (output)
    document.getElementById("synonyms").innerHTML = output;

Here is the live demo, that you will be able to see only on JSON capable browsers:

Synonyms of peace:
please wait...

jQuery based request

jQuery is a powerful javascript library designed to simplify the client-side scripting of HTML.
The following code snippet shows how to perform ajax request to get synonyms:

  url: "", // NOTE: replace test_only with your own KEY
  success: function(data){
    if (data.length != 0) {
      output = "";
      for (key in data.response) {
        output += data.response[key].list.synonyms+"<br>";
    } else $("#div1").html("empty data");
  error: function(xhr, status, error){
    $("#div1").html("An error occured: " + status + " " + error);

The live demo using jQuery is available here.
Share Share on Facebook Share on Twitter Bookmark on Reddit Share via mail
Terms and conditions | Privacy policy