views:

997

answers:

1

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?

+3  A: 

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).

Darin Dimitrov
Thanks! The alert had just been showing me comma separated values (God knows why), but it turned out to be strings in a list. It's fixed now.
OwenK