def METHOD_NAME(request):
    # Request is AJAX when done with XMLHttpRequest
    if request.headers.get("x-requested-with") == "XMLHttpRequest":
        return True
    # Assume that request is AJAX when it has JSON payload
    return "application/json" in request.headers.get("content-type", "")