I am using Django REST framework to create an API. It is working fine with cURL.
curl -H 'Accept: application/json; indent=4' -u ratan:qazwsxedc123 http://127.0.0.1:8000/api/grocery/subcategories/
However, when I try to use jQuery to populate a div
in a HTML page it is not working, I am getting a 403 forbidden error.
This is my code.
$.ajax({
url: "http://127.0.0.1:8000/api/grocery/subcategories/?format=json",
type: "GET",
dataType: "json",
data: {
username: "ratan",
password: "qazwsxedc123"
},
success: function(data) {
console.log('ratan');
},
});
I thought it can be because of CORS, so I have tried django-cors-headers
, but it didn't help.