I tried to hit the API using an ajax call. but it's throwing this Error (from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request). I add cores headers settings in Django settings and headers also added in ajax call. but I could not get the data throwing the same error.
Ajax Code
$.ajax({
url: "{{ api.endpoint }}",
type: "GET",
beforeSend: function(request) {
request.setRequestHeader("Access-Control-Allow-Origin", 'http://127.0.0.1:8000');
},
data: {
"limit" : 1,
"api_key" : "{{ api.token }}"
},
success: function(data) {
alert("Your Connection is successful. Retrieved " + data.length + " records from the dataset!");
},
error: function(err) {
console.log(err)
alert("Connection Failed.");
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…