使用ajax和php将页面重定向到两个不同的位置

时间:2016-08-02 21:52:58

标签: php jquery ajax

重定向有问题,我有2个按钮,想要以不同方式重定向,但代码无效。

请在我的代码中提供解决方案或任何错误。

这是代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post">
<?php
include("./config.php");
         $sql="Select cat_id,cat_name from category";
             $result=mysqli_query($con,$sql) or die(mysql_error()."no data");
            ?>
            <select name="cat" id="cat">
                        <option value=0>Select Category</option>
                    <?php
                        while($row=mysqli_fetch_row($result))
                     {
                 ?>
                  <option value="<?php echo $row[0];?>"><?php echo $row[1];}?></option>
                    </select>
      </form>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
 <script>
 function makeAjaxRequest(cate){
        $.ajax({
          type: "POST",
          data: { cat: cate }, 
          url: "fetchmenu.php",
          success: function(data) {
           $('#showresult').html(data);
          }
        });
      }

 $("#cat").on("change", function(){
        var id = $(this).val();
          makeAjaxRequest(id);

      });
 </script>
<div id="showresult">

</div>

</body>
</html>

以上代码用于选择类别,现在在类别选择上,我将从数据库中获取具有两个选项的项目编辑和删除按钮。

fetchmenu.php

<?php

include("config.php"); 
$ct = $_REQUEST["cat"];
$sql="Select item_id,item_name,item_image from item_list where c_id='$ct'";
$result=mysqli_query($con,$sql) or die(mysql_error()."no data");
            echo  "    <form method='post' enctype='multipart/form-data' action=''>
            <table cellspacing='5px' width='auto' align='center' style='margin-left:5%'>

";             while($row=mysqli_fetch_row($result))
             {

    echo "<tr>   
        <td style='width:100px;'>
        <img src='".$row[2]."'alt='' name='upload' height='100px' width='100px'/></td>
        <td>
        '".$row[1]."'</td>";

      echo "<td style='vertical-align:middle;'><button type='button' name='ect' value='ect_".$row[0]."' style='margin-left:80px;border:none;background-color:#ff7143; color:#353534;height:30px;width:100px; margin-bottom:20px;' onclick='editmenu.php'>Edit</button>   </td>
";      
  echo "
       <td>
       <button type='button' name='dlet' id='dlt' value='dlt_".$row[0]."' style='margin-left:80px;border:none;background-color:#ff7143; color:#353534;height:30px;width:100px;margin-bottom:20px;' onclick='deletemenu.php'>Delete</button>";}
       echo "    
       </td>
        </tr>       
        </table>
        </form>";

  ?>

我如何将它们重定向到2个不同的页面,它不是通过ajax工作,也不是直接工作,它不起作用,即当我写onclick =&#34; editmenu.php&#34;时。 请有人给出解决方案,我真的卡住了。

1 个答案:

答案 0 :(得分:0)

你将把一个计时器放在一个触发器函数中,如:

rewrite ^/admin/((?!popups).)*/([a-zA-Z0-9_-]+\.php?)$ /route.php?_route_url=$uri&$args last;