dongshan3806 2015-01-01 18:08 采纳率: 0%
浏览 452

javascript location.replace不起作用

I have this code:

<?php
include 'theme.php';
css();
if($_POST['wget-send'])
    {
    $formdir=$_POST['dir'];
    $formlink=$_POST['link'];
    $filelink = fopen('/root/wget/wget-download-link.txt',a);
    $filedir = fopen('/root/wget/wget-dir.txt',w);

    fwrite($filedir, $formdir);

    /*
    fwrite($filelink, $formlink."
");
    exec('touch /root/wget/wget-download-link.txt',$out);
    exec('echo "'.$dir.'" > /root/wget/wget-dir.txt',$out);
        */

    exec('echo "'.$formlink.'" > /root/wget/wget-download-link.txt');
    exit();
    }
echo "<form action=\"".$PHP_SELF."\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link:';
echo ("<textarea name=\"link\" rows=\"13\" cols=\"62\"></textarea><br><br>");
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Send" id="WgetID"/>';
echo "</form></div>";
echo <<<HTML
<script type="text/javascript">

function LinkAdded()
    {
            alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
            location.replace("wget_log.php");
    }
</script>
HTML;
foot();
echo '
</div>
</body>
</div>
</html>';
?>

the alert part works it gives me a pop up but after the pop up, it just gives me a blank page. How do I make the location.replace("wget_log.php"); work?

stackoverflow keeps telling me that I should add more details on my post but I think that's all the details I can give.

  • 写回答

1条回答 默认 最新

  • dongyong8491 2015-01-01 18:15
    关注

    You need to prevent the default action of submitting the form by returning false from the click handler

    echo '<input type="submit" onclick="LinkAdded(); return false;" name="wget-send" value="Send" id="WgetID"/>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?