I have an api sitting in front of AGS that requires it's own authentication. I am using setRequestPreCallback as stated by the ESRI docs.
In the image below, you can see that the first 2 requests are returning 200. The first request is CORS Preflight and the second request is the JS api getting the json info from the MapServer.
The second request uses the function I have set in setRequestPreCallback(...) to properly set a header value with the token. However, whenever an image is requested from the MapServer (via export), the function I have in setRequestPreCallback is not called and the token is not set, leaving me with a bunch of 401 Unauthorized requests.
Feel free to answer on SO as well: http://stackoverflow.com/questions/32238110/setrequestprecallback-is-partially-working
Message was edited by: Brad Janke