I'm working on a web application that has a video page and a Web API for logging purposes. The events are triggered using an ajax post request:
function logAction(actionToLog) {
$.ajax({
type: 'POST',
url: "/api/v/" + currentVideoName + "/" + currentUser + "/" + vid.currentTime + "/" + actionToLog + "/" + currentBrowserType + "/",
cache: false,
contentType: 'application/json; charset=utf-8'
});
Upon inspecting the calls in Fiddler, I noticed that each call is being duplicated:
First Request (Unauthorized 401) without authorization token:
POST http://HOSTNAME/api/v/ValuePropVideo1/tfrick/0/started/Chrome/ HTTP/1.1
Host: HOSTNAME
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: */*
Origin: http://HOSTNAME
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Content-Type: application/json; charset=utf-8
Referer: http://HOSTNAME/v/ValuePropVideo1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Second Request (valid) with authorization token:
Authorization: Negotiate YIII+QYGKwYBBQUCo...
Logging page load and video completion events works fine as the browser remains open. However, when triggering the call for user closing the browser, only the first request is sent resulting in a 401 error.
My query is: How can I ensure these ajax calls are made using the Windows credentials?