Paul Phoenix
Paul Phoenix

Reputation: 1433

Loading json data to div using jquery ajax call

Can anyone please tell me what is wrong with the given below code. I am trying to load data in a div using json call.

function getData() {
    $.ajax({
        url: "http://echo.jsontest.com/key/value/one/two",
        type: "get",
        dataType: "JSON"
    }, function(data){
        $('#99').append(JSON.stringify(data));
    });
    return false;
}

It would be great if someone can put some light on $.ajax, $.get, $.post and $.getJSON

Upvotes: 1

Views: 22998

Answers (1)

Louay Alakkad
Louay Alakkad

Reputation: 7408

You're mixing $.get and $.ajax

Use this instead:

$.ajax({
    url: "http://echo.jsontest.com/key/value/one/two",
    dataType: "json"
}).success(function(data){
    $('#data').append(JSON.stringify(data));
});

Demo: http://jsfiddle.net/j3vsg/

Upvotes: 6

Related Questions