jQuery的阿贾克斯引荐网址 [英] jQuery ajax referer url
问题描述
我怎样才能得到的引用者的URL在一个Ajax请求?
How can I get the url of the referer in an ajax request?
一个名为main.php有jQuery的发送一个AJAX调用一个名为request.php。
A file named main.php has jQuery that sends an ajax call to a file named request.php.
是否有可能以某种方式计算出的引荐,当我在request.php?为了precise,我想打印字符串main.php(动态)在运行request.php。
Is it possible to somehow figure out the referer when I'm on request.php? To be precise, I want to print the string "main.php" (dynamically) while running request.php.
推荐答案
通常情况下,浏览器将使用标题发送引用者页面引用站点
作为Ajax请求的一部分,因此你可以阅读
Normally the the browser will send the referer page using the header Referer
as part of the ajax request so you can read it
所以,你可以不喜欢
$_SERVER['HTTP_REFERER']
- 你如何在PHP中的引荐头?
- How do you get the 'referer' header in PHP?
如果你不希望依赖于默认引用站点
头,通过自己的自定义标题
If you don't want to depend on the default Referer
header, pass a custom header of your own
$(document).ajaxSend(function (event, jqXHR) {
jqXHR.setRequestHeader('my-referer', 'some-value');
});
这篇关于jQuery的阿贾克斯引荐网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!