开发者

php, jquery, load function and page address

开发者 https://www.devze.com 2023-01-22 17:32 出处:网络
i have two files. In first (parent, address: www.myaddress.com/fun/test.php) is jQuery function: <script type=\"text/javascript\">

i have two files. In first (parent, address: www.myaddress.com/fun/test.php) is jQuery function:

<script type="text/javascript">         
$(function(){
    $(document).ready(function()
    {
        import_f = setInterval(function()
        {
            $('#file')开发者_运维问答.load('fun2.php?id='+ Math.random());

        }, 5000);       
    });
});         
</script>

When i print in fun2.php file full page address, i get: /fun2.php?id=0.31089064538474454.

How get paren page address. (www.myaddress.com/fun/test.php).

Parent's address may always be another, so I need to find a function that.

Thanks


is this what your looking for?

function getParentAddress(){
  return window.location;
}


Sounds like you are looking for the HTTP Referrer. You can get it via $_SERVER['HTTP_REFERER'].

But note that this can be changed by the user to something else, so you actually cannot rely on that.


Maybe it is better to send the current URL via the Ajax call, along with the ID:

$('#file').load('fun2.php?id='+ Math.random() +'&parent=' + encodeURIComponent(window.location));

But again, if one really wants to, he can change this too. So you can never 100% trust that one request is really coming from a certain page.

Reference: window.location, encodeURIComponent


The current address of the page is stored in the window.location property.

console.log(window.location)

run on this page yields

hash: ""
host: "stackoverflow.com"
hostname: "stackoverflow.com"
href: "http://stackoverflow.com/questions/4031148/php-jquery-load-function-and-page-address"
origin: "http://stackoverflow.com"
pathname: "/questions/4031148/php-jquery-load-function-and-page-address"
port: ""
protocol: "http:"
search: ""
0

精彩评论

暂无评论...
验证码 换一张
取 消