简体   繁体   English

点击按钮刷新另一个网址

[英]refresh another url by clicking button

hi can anyone help me with this prob, 嗨,有人能帮我这个问题吗?

suppose m working with employee/refresh1.php in which i have a button as follows 假设我正在与employee / refresh1.php一起工作,其中我有一个按钮,如下所示

when i click on this submit button employee/refresh2.php has to refresh 当我单击此提交按钮employee / refresh2.php必须刷新

in refresh2.php i have followinf func 在refresh2.php中,我具有followinf函数

echo(rand(10,100));

so onclick of submit button new random numbers has to be generated. 因此onclick提交按钮必须生成新的随机数。 i have seen several functions but it helps in refreshing same page but my problem is i have refresh another page onclick of submit button which is in different page. 我已经看到了几个功能,但是它有助于刷新同一页面,但是我的问题是我已经在不同页面中的提交按钮上单击了另一个页面。

You have to give name to new window when you open, then call onClick event [name of new window].location.href = href; 打开时必须给新窗口命名,然后调用onClick事件[新窗口的名称] .location.href = href; href will be url of new page that you want to refresh. href将是您要刷新的新页面的url。

This will refresh the div and print the output of refresh2.php in refreshDIV . 这将刷新div并在refreshDIV output refresh2.phpoutput

<script type="text/javascript">
    $(document).ready(function(){

        $("#refreshDIV").click(function(){
           $("#refreshDIV").load('refresh2.php');
        });
    });
</script>

<div id="refreshDIV">
    Click here to load
</div>

what do you mean by refreshing the employee/refresh2.php page??? 刷新 employee / refresh2.php页面是什么意思??? does it mean that every time you click the button, you get redirected to that page and it shows the output you want...or instead that the current page fetches the new random values every time from the employee/refresh2.php page and show it to you on employee/refresh1.php page??? 这是否意味着每次单击该按钮,您都将重定向到该页面 ,并显示您想要的输出...或者相反,当前页面每次都从employee / refresh2.php页面获取新的随机值并显示它在employee / refresh1.php页面上给您?
If latter is the case then you need to learn the basics of ajax... 如果是后者,那么您需要学习ajax的基础知识。
suppose this is the coding in your employee/refresh.html page 假设这是您的employee / refresh.html页面中的编码

     <body>
        <input type="submit" onclick="dothis()"> 
        <script>
    function dothis()
    {
        if(windows.XMLHttpRequest)
        {
        xmlhttp=new XMLHttpRequest();
        }
        elseif(windows.ActiveXObject)
        {
        xmlhttp=new ActiveXObject();
        }
        xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4)
        {
        document.getElementById("demo").innerHTML=xmlhttp.responseText;
        }

        }
 $url="employee/refresh2.php?q";
        xmlhttp.open("Get",$url,true);
        xmlhttp.send(null);
    }
        </script>
        <div id="demo"></div>

        </body>

    and then on employee/refresh2.php page do this<br>

        <?php if(isset['q'])
        echo (rand(10,100));
        ?>

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

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