Anyone knows if with jquery or general javascript, I can change the referrer from the header in an http ajax call?
basically I want it to be sent from my page but ha
You can't do that with jQuery, but you CAN do that with fetch
Not sure if it would work for cross domain requests (you will obviously need at least CORS permissions for that) but it definitely does work for same domain + different page like in this example
fetch("http://example.com",{"referrer":"http://example.com/inbox","body":"{\"format\":\"root\"}","method":"POST"});
You can always use this :
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("header key", "header value")}
})
But ofcourse, the browser can have a different opinion about the referer header. This should be tested :)
You can use .setRequestHeader( 'referer', 'foo' )
, but I'm not sure if the browser would just replace that with the proper one or not.
via jQuery, the .ajax()
method allows headers as well (.get()
and .post()
don't)
Note that there's very little point to doing this as you can't do cross-domain AJAX and even attempting to do this could possibly trigger XHR security rules in some browsers and just stop the request altogether.
The browser will overwrite the referrer always for the tests that I've done. Meaning you can't change the referrer of an ajax call.