how to return a dictionary in python django and view it in javascript?
Very simply:
import json
data = {'val1' : 'this is x', 'val2' : True}
return HttpResponse( json.dumps( data ) )
You can not directly use the python object you have to convert it into JSON string first Look into following documentation.
http://docs.python.org/library/json.html also http://www.json.org/
JSON is easiest way to transfer data(also you can use XML).
In python:
import json data = {'val1': "this is x", 'val2': True} return HttpResponse(json.dumps(data))
In javascript:
function (data) { data = JSON.parse(data); if (data["val2"]) { alert(data["val1"]); } }