I'm working with an endpoint that seems to be built on Django.
Attempting to setup basic aJax communication to it via POST I wrote:
jQuery.ajax({
type: "POST",
url: "http://API-ENDPOINT-URL",
data: "",
dataType: "json",
crossDomain: false,
beforeSend: function(xhr){
xhr.withCredentials = false;
xhr.setRequestHeader('Authorization', 'Token <TOKEN THAT I WAS PROVIDED>' );
},
success: function(results)
{
reqListener(results)
}
});
With those code a few things happened:
2.I get this error in the console:
XMLHttpRequest cannot load http://API-ENDPOINT-URL. Response for preflight has invalid HTTP status code 401
{"detail":"Authentication credentials were not provided."}
What am I missing? Am I incorrectly sending the authentication token?
Doing token auth via Javascript without CORS enabled is a suicide mission.
Do yourself a favor like I did and just do it via server side.