I'm trying to return a JSON response from a Django view call via an ajax call like below:
var tab = 'test';
var response = $.ajax({
url: "/" + tab + "/"
}).responseText;
alert(response);
Here is my Django view:
if request.is_ajax() == True:
req = {}
req['html'] = '<b>This is a test</b>'
response = simplejson.dumps(req)
print response
return HttpResponse(response, mimetype="application/json")
else:
return render_to_response("ajax/pingpong.html", {'ajax': ajax})
For some odd reason, the alert box is blank (though it does not say undefined in it). Interestingly enough, $.post and $.getJSON work fine on the exact same URL. I also see the expected JSON output on my console. Any help would be appreciated!