Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过单击按钮刷新另一个url_Javascript_Php_Html - Fatal编程技术网

Javascript 通过单击按钮刷新另一个url

Javascript 通过单击按钮刷新另一个url,javascript,php,html,Javascript,Php,Html,嗨,有人能帮我解决这个问题吗 假设我使用employee/refresh1.php,其中有一个按钮,如下所示 当我点击这个提交按钮时,employee/refresh2.php必须刷新 在refresh2.php中,我使用了followinf func echo(rand(10,100)); 因此,只要点击提交按钮,就必须生成新的随机数。我见过几个函数,但它有助于刷新同一页面,但我的问题是,我在单击不同页面中的提交按钮时刷新了另一个页面。打开新窗口时,您必须给新窗口命名,然后调用onclic

嗨,有人能帮我解决这个问题吗

假设我使用employee/refresh1.php,其中有一个按钮,如下所示

当我点击这个提交按钮时,employee/refresh2.php必须刷新

在refresh2.php中,我使用了followinf func

echo(rand(10,100));

因此,只要点击提交按钮,就必须生成新的随机数。我见过几个函数,但它有助于刷新同一页面,但我的问题是,我在单击不同页面中的提交按钮时刷新了另一个页面。

打开新窗口时,您必须给新窗口命名,然后调用onclick事件[name of new window]。location.href=href;
href将是您要刷新的新页面的url

这将刷新div并在refreshDIV中打印refresh2.php的输出

刷新employee/refresh2.php页面是什么意思???这是否意味着每次单击按钮时,您都会被重定向到该页面并显示您想要的输出…或者当前页面每次都从employee/refresh2.php页面获取新的随机值,并在employee/refresh1.php页面上显示给您??? 如果是后者,那么您需要学习ajax的基础知识。。。 假设这是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));
        ?>

您的代码只会在屏幕上显示一个随机数。它与页面刷新有什么关系?您正在使用父窗口?它必须在每次您应该使用它对refresh2进行异步调用时生成新的随机数。phpbetter u只刷新包含随机数生成器功能的特定DIV
     <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));
        ?>