OwenK
OwenK

Reputation: 163

Problems with jquery append and json data

I'm having trouble making this work:

$(function() {
    $(".button").click(function() {
        var newentry = $("input#entry").val();
        $.getJSON("/dictionary_request/", {entry: newentry}, function(json){
            $("span").empty();
            alert(json);
            $("span").append(json);
        });
    });
});

The JSON request, the emptied span, and the alert all work fine, but the append doesn't. I'm assuming it's some kind of type error. How can I make it work?

Upvotes: 1

Views: 2337

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039588

The append method expects a string or DOM node as argument. You are calling it with an object (json). The contents of this object will depend on the data sent by the server. What does the alert print on your screen? Using FireBug you can inspect the properties available to your json object: console.log(json).

Upvotes: 3

Related Questions