jquery json null when using localhost
- by Eeyore
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')