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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.