简体   繁体   English

jQuery ajax引用网址

[英]jQuery ajax referer url

How can I get the url of the referer in an ajax request? 如何在ajax请求中获取引荐来源网址?

A file named main.php has jQuery that sends an ajax call to a file named request.php. 名为main.php的文件具有jQuery,该jQuery将ajax调用发送到名为request.php的文件。

Is it possible to somehow figure out the referer when I'm on request.php? 当我在request.php上时,是否有可能找出引荐来源网址? To be precise, I want to print the string "main.php" (dynamically) while running request.php. 确切地说,我想在运行request.php时(动态)打印字符串“ main.php”。

Normally the the browser will send the referer page using the header Referer as part of the ajax request so you can read it 通常,浏览器将使用header Referer作为ajax请求的一部分发送Referer ,因此您可以阅读它

So you could do something like 所以你可以做类似的事情

$_SERVER['HTTP_REFERER']

If you don't want to depend on the default Referer header, pass a custom header of your own 如果您不想依赖默认的Referer标头,请传递自己的自定义标头

$(document).ajaxSend(function (event, jqXHR) {
    jqXHR.setRequestHeader('my-referer', 'some-value');
});

是的,在request.php上可以得到这样的裁判$ _SERVER ['HTTP_REFERER']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM