-2

I have an html file with json request. I cannot make json show the result. What's the mistake i have?

<p id="syno"></p>

That is where i should see the result and below is the script for that

<script>
var apiUrl = 'http://words.bighugelabs.com/apisample.php?v=2&format=json';
$.ajax({
    url: apiURL,
    type: "GET",
    dataType: 'json'});
  success: function (response) {
            // The request succeeded
            console.log(response);
            parseWord(response);

        },
        error: function (xhr, status) {
            // The request failed
            console.log(status);

            showError();
        }

function parseWord(data) {

$('#syno').text(noun.ant);
}

</script>
Alan Ferd
  • 1
  • 2
  • 2
    what is noun? Where is parseWord called? – ryanlutgen Dec 08 '14 at 02:00
  • copy that data in the raw text format and save it as a `.json` or use `jQuery.parseJSON( data )` – Rafael Dec 08 '14 at 02:00
  • noun is a category in the json response – Alan Ferd Dec 08 '14 at 02:01
  • 1
    Add `success: parseWord` to your AJAX config object and make it `.text(data.noun.ant)` – Phil Dec 08 '14 at 02:02
  • possible duplicate of [How to return the response from an Ajax call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Phil Dec 08 '14 at 02:03
  • 1
    You have to provide a `success` handler to `ajax` call and use the response there. Mind the cross-domain restriction on `json` requests - http://api.jquery.com/jquery.ajax/ – Igor Dec 08 '14 at 02:04

1 Answers1

-1

The function parseWord(data) never gets called. If you want parseWord(data) to run if the ajax request is successful, you have to do something like this:

$.ajax({
    url: apiURL,
    type: "GET",
    dataType: 'json',
    success: function parseWord(data) {
               $('#syno').text(data.noun.ant);
             }
});

I would suggest you take a look at the documentation on this

cbalos
  • 879
  • 1
  • 9
  • 19
  • The problem is his callback isn't using the argument `data` at all. It should be `data.noun.ant` – Menztrual Dec 08 '14 at 02:06
  • @BrendanScarvell He updated his question before right before i responded, but yes you are correct. See my updated answer. – cbalos Dec 08 '14 at 02:07