使用Django和Ajax

I am trying to send request data using ajax to my backend server consist of python & django

Python Code

views.py

 def JSON_Sample(request):
    response_data = {}
    response_data['result'] = "Success"
    response_data['message'] = "AJAX Worked"
    return JsonResponse(response_data)


AJAX request

AJAX request

$.ajax({
        url:"http://localhost:8000/login/json",
        dataType:"jsonp",
        success:function(response){
            alert("finaly sucess");
        }
    });

Error in this is cross origin request blocked. I am newbie in it please help me out what should i do in my code ?

CORS is a mechanism for allowing clients to interact with APIs that are hosted on a different domain.

You can use "django cors headers" to fix your problem:

https://github.com/ottoyiu/django-cors-headers/