dua6992 2015-02-07 19:00
浏览 38

似乎无法重定向

I'm trying to go to the deleteQns.php page from my code, but I can't seem to go there as I'm always redirected back to administrator(Quiz2). I don't know what's wrong. I hope you all will be able to help me.

Here is my code:

<?php while($row=$ result->fetch_array(MYSQLI_ASSOC)) { ?>
<tr class="size">
  <form id="button" action="administrator(Quiz2).php" method="post">
    <th>
      <p>No.
        <?=$row[ "questionid"]?>
      </p>
    </th>
    <th>
      <?=$row[ "questiontext"]?>
    </th>
    <th class="editanddelete">
      <input type="hidden" name="qid" value="<?=$row[" questionid "]?>">
      <input type="submit" value="Edit" name="editbtn">
  </form>
  <form id="delete" action="deleteQns.php" method="post">
    <button onclick="myFunction()">Delete</button>
    <input type="hidden" name="qid" value="<?=$row[" questionid "]?>">
    <p id="demo"></p>
    <script>
      function myFunction() {
        var x;
        if (confirm("Are You Sure You Want To Delete This Question?") == true) {
          window.location = "deleteQns.php";
        } else {
          x = "";
        }
        document.getElementById("demo").innerHTML = x;
      }
    </script>
  </form>
  <?php } ?>
  • 写回答

1条回答 默认 最新

  • dsu5188 2015-02-07 19:02
    关注

    Problem occurs here:

    window.location = "deleteQns.php";
    

    You cannot be redirected because window.location is object with several functions for working with web protocol of the page. So when you want to change it, the best way how to do it

    window.location.href = window.location.hostname+"/deleteQns.php";
    

    For example this is equal to : http://google.com/deleteQns.php

    You can read more about window.location: MDN

    Another way how to check if your code doesn't work is console.

    Windows: <kbd>CTRL</kbd>-<kbd>SHIFT</kbd>-<kbd>J</kbd>

    Mac: <kbd>⌥</kbd>-<kbd>⌘</kbd>-<kbd>J</kbd>

    Also available through the wrench menu (Tools > JavaScript Console):

    JavaScript Console Menu

    (Answer by Runscope API Tools)

    And here you can debug like this:

    <button onclick="myFunction()">Delete</button>
    <input type="hidden" name="qid" value="<?=$row[" questionid "]?>">
    <p id="demo"></p>
    <script>
        function myFunction() {
            var x;
            var confirmed = confirm("Are You Sure You Want To Delete This Question?");
            /* For logging data to console */
            console.log(confirmed);
            if (confirmed == true) {
                window.location.href = window.location.hostname+"/deleteQns.php";
            } else {
                x = "";
            }
            document.getElementById("demo").innerHTML = x;
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)