I fetch script with
$.getScript("http://www.example.org/file.js");
However, the referer goes empty to that site. How can I use referer (can be antyhing) instead of empty referer ? Note: Using getscript is required, I cant use script src="".
I fetch script with
$.getScript("http://www.example.org/file.js");
However, the referer goes empty to that site. How can I use referer (can be antyhing) instead of empty referer ? Note: Using getscript is required, I cant use script src="".
You can send headers using directly .ajax()
. From documentation:
jQuery.getScript()
is a shorthand Ajax function, which is equivalent to:
$.ajax({
url: url,
dataType: 'script',
success: function(data){
console.log(data);
}
});
From here, we can use the headers
setting and we get something like this:
$.ajax({
url: url,
dataType: 'script',
headers: {'X-Alt-Referer': location.href },
success: function(data){
console.log(data);
}
});
This answer can help you too.
You can do it like this
function GetScript(url)
{
$.getScript(url)
.done(function(script, textStatus)
{
console.log( textStatus );
})
.fail(function( jqxhr, settings, exception ) {
console.log(exception);
return GetScript("http://www.example.org/file_2.js");
});
}
GetScript("http://www.example.org/file.js");