1

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="".

user198989
  • 4,574
  • 19
  • 66
  • 95
  • What are you trying to do exactly? Send a header through AJAX to the target site to inform from where the call comes or any other data? – kosmos Aug 03 '15 at 18:13

2 Answers2

3

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.

Community
  • 1
  • 1
kosmos
  • 4,253
  • 1
  • 18
  • 36
2

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");
Omran Shagooj
  • 77
  • 1
  • 6