I am trying to send a api call from my javascript with contentType: "application/x-www-form-urlencoded", But the call also requires we to include the session-token to be included in the header and when I do both of them together it gives me error. How to send both of header and content type together?
Request:
function g_ajaxerV2Receive(url_str, ok_cb, fail_cb){
$.ajax({
url: url_str,
type: "POST",
crossDomain: true,
data: "",
success: ok_cb,
error: fail_cb,
timeout: 60000,
dataType: "json",
contentType: "application/x-www-form-urlencoded",
headers: {
"Session-Token:" + String(SessionToken), //Token is in variable
}
});
}
The error that I get when both contentType and Header exist:
Access to XMLHttpRequest at 'https://API-URL' from origin 'http://127.0.0.1:5505' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
And the requirement for the call is that we need both The session token and the application/x-www-form-urlencoded.
The allowed CURL requestExample:
curl 'https://URL-HERE'
-H 'Session-Token: session_token_here'