1👍
Your view should be like this,
def json_data(request):
if request.is_ajax():
message = "Yes, AJAX!"
else:
message = "Not AJAX"
return JsonResponse(dict(message, message))
Also, your ajax request should be,
If you are on the result view,
$.ajax({
type: "GET",
url: "/help/",
success: function(data){
alert(data);
$("body").append(data);
}
});
0👍
The first thing to fix is the typo in the URL of the jquery CDN – it should be:
http://code.jquery.com/jquery-latest.min.js
not
http://code.jquery.com/jquery-lastest.min.js
i.e. ...latest...
not ...lastest...
.
Without jquery the ajax call has no chance of working.
Source:stackexchange.com