jquery json null when using localhost

Posted by Eeyore on Stack Overflow See other posts from Stack Overflow or by Eeyore
Published on 2010-06-10T02:01:20Z Indexed on 2010/06/10 2:12 UTC
Read the original article Hit count: 462

Filed under:
|
|

I am trying to load json generated by my django app. It works when I save the json output and load it from a static file. However, when I make a call to a server it returns null.

JSON

{"users": [
    {
        "id": 1,
        "name": "arnold"
    }, 
    {
        "id": 2,
        "name": "frankie"
    }
]}

Ajax call

$.ajax({
    url: "http://localhost:8000/json",  //vs. json.js
    dataType: 'json',
    type: 'get',
    timeout: 20000,
    error: function() {
        alert("error");
    },
    beforeSend: function() {
        alert("beforeSend");
    },
    complete: function() {
        alert("complete");
    },
    success: function(data) {
        alert(data.users[0].name);
    }
});

view.py

return HttpResponse(simplejson.dumps(data), content_type = 'application/json; charset=utf8')

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about django