Context: a chrome browser extension uses JQuery to request a response from a remote django app. Django recognizes that the request is made via AJAX and responds with "Hello AJAX!". I'm basing my exercise off this great example. Because this request is being made from a chrome extension, the request is being made cross site, so I've used the @CSRF_exempt decorator on my Django view.
Problem: My Django view is not recognizing the request as an AJAX request, and instead of responding Hello AJAX! it responds Hello not AJAX!.
My Django view:
(The url /xhr_test uses the following view)
@csrf_exempt
def check_login_extension(request):
if request.is_ajax():
message = "Hello AJAX!"
else:
message = "Hello not AJAX"
return HttpResponse(message)
My JQuery request:
function xhrconnect() {
$.get("http://localhost:8000/xhr_test", function(data) {
document.getElementById('xhrmsg').innerHTML = (data);
});
}