I'm trying to add header to request in Ajax with JQuery.
Below is the code :-
$.ajax({ type: "POST", contentType: "application/json", url: "http://localhost:8080/core-service/services/v1.0/patients/registerPatients", data: JSON.stringify(patientDTO), //crossDomain : true, dataType: 'json', headers: {"X-AUTH-TOKEN" : tokken}, success: function(patientDTO) { console.log("SUCCESS: ", patientDTO); /* location.href = "fieldagentHRA.html";*/ if (typeof(Storage) !== "undefined") { localStorage.setItem("patUrn", patientDTO.data); location.href="fieldagentHRA.html"; } }, error: function(e) { console.log("ERROR: ", e); display(e); }, done: function(e) { enableRegisterButton(true); } });
I inspected this with chrome and found that header's body is not being added.
Then I used Requestly (Requestly is chrome+firefox plugin with which we can manually add a header to the request).
After manually adding header :-
In both the pics request header x-auth-token is present in "ACCESS-CONTROL-REQUEST-HEADERS" but "X-AUTH-TOKEN" header along with header value is present in second pic which is not there in the first pic.
So my question is how to add request headers in Ajax with JQuery ?