I am trying to track all requests made through an application by setting a custom request header on all outgoing requests. I was able to accomplish this using:
$ajax.Setup(
beforeSend: ...
However, I ran into an issue when the src attribute on a dom element (i.e. iframe, video, object, etc) was initiating the request. When searching I had found: How to set custom http headers when changing iframe src? However, when I attempted this, I was unable to get it to initiate the download dialog. That code looked like:
var request = $.ajax({
context: this,
url: URI,
type: 'GET',
statusCode: {
200: function(data) {
var id = '#download-iframe';
var $iframe = $(id);
if($iframe.length === 0) {
$iframe = $('<iframe>')
.attr('id', 'download-iframe')
.appendTo('body');
}
$iframe.contents().find('html').html(data);
}
}
});
The response headers for that request look as follows:
Content-Disposition:attachment; filename="PDF.pdf"
Content-Length:86712
Content-Type:application/pdf;charset=UTF-8
This displayed the raw data in the iframe, but did not initiate the download.
Is there anyway to either A) (preferred) Set the request headers a different way via setting the DOM element src or B) Get the download dialog to initiate.