2014-12-31 37 views
2

我正在做一個搜索功能使用範圍滑塊使用jquery &阿賈克斯在Php。在jquery中如何重定向到另一個頁面?

我可以從數據庫中獲取數據並顯示在同一頁面中,但我需要在其他頁面中顯示數據。

我的索引頁:

<html> 
    <head> 
     <title></title> 
     <style> 
      tr { border:1px solid #066;} 
      tr th { border:1px solid #eeeeee; padding:5px; background:#e1e1e1;} 
      tr td { border:1px solid #eeeeee;} 
     </style> 
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
     <link rel="stylesheet" href="style.css" /> 
     <script> 
      $(function() { 
       $("#slider-range").slider({ 
        range: true, 
        min: 0, 
        max: 1000, 
        values: [0, 500], 
        slide: function (event, ui) { 
         $("#amount").val("Rs." + ui.values[ 0 ] + " - Rs." + ui.values[ 1 ]); 
         var from = ui.values[ 0 ]; 
         var to = ui.values[ 1 ]; 
         $.ajax({ 
          type: "POST", 
          url: "get_data.php", 
          data: "from=" + from + "&to=" + to, 
          success: function (html) { 
           $("#response").html(html); 
           //window.location="index1.php"; 
          } 
         }); 
        } 
       }); 
       $("#amount").val("Rs." + $("#slider-range").slider("values", 0) + " - Rs." + $("#slider-range").slider("values", 1)); 
      }); 
     </script> 
    </head> 
    <body> 
     <div style="width:280px; padding:10px;"> 
      <h5>Price Range:</h5> 
      <div id="slider-range"></div> 
      <input type="text" id="amount" class="ttt" style="margin-left:70px"> 
      <div id="response"></div> 
     </div> 
    </body> 
</html> 

我GET_DATA代碼:

<table> 
    <tr> 
     <th>Name</th> 
     <th>Address</th> 
     <th>City</th> 
    </tr> 
    <?php 
    $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); 
    mysql_select_db("details", $conn) or die(mysql_error()); 
    $formprice = $_POST['from']; 
    $toprice = $_POST['to']; 

    $query = "SELECT * from details where hallcapacity between '" . $formprice . "' and '" . $toprice . "'"; 
    $res_cart = mysql_query($query); 
    while ($row_cart = mysql_fetch_array($res_cart)) { 
     ?> 
     <tr> 
      <td><?php echo $row_cart['name']; ?></td> 
      <td><?php echo $row_cart['address']; ?></td> 
      <td><?php echo $row_cart['city']; ?></td> 
     </tr> 
     <?php 
    } 
    ?> 
</table> 

在索引頁成功函數之後我用window.location的功能,但在移動幻燈片重定向到與其他出頁面獲得價值。請給出任何建議。

+0

那麼爲什麼要使用jQuery AJAX? – Priyank

+0

多數民衆贊成我是問,如果你想重定向頁面,那麼爲什麼你使用ajax-jquery – Priyank

+0

也設置'數據:「從=」+從+「&到=」+到'值當點擊到下一頁按鈕,並在頁面加載時檢測該參數,另一種替代解決方案是使用pushHistory api更改網址而不刷新頁面。 –

回答

2

如果你只是想通過window.location到參數傳遞到另一個頁面,您可以做到這一點:

winndow.location.href = 'new_page.php?param1=one&param2=two&...'; 

,並獲得新的一頁PARAMS用php:

$ param1 = $ _GET ['paramm1']; $ param2 = $ _GET ['paramm2'];

0

任何你將如何AJAX成功後嘗試一下本作重定向:

var a = data; 

window.location.href ="window.location.href="index.php?data="+a"; 

在index1.php

<?php 
if (isset($_GET["data"])){ 
echo $_GET['data']; 
} 
?> 
+0

@Janani:你有我的回答 – Priyank

+0

我用它這是重定向到其他頁面,但沒有得到任何價值它是重定向@Priyank – Janani

+0

@Janani:現在試試!!!!我認爲它的工作:) – Priyank

0

由於您需要將數據顯示在另一個頁面中,因此您無需使用ajax。您可以通過url傳遞所需的參數並獲取相應頁面函數中的參數值。您能redirect這樣

slide: function(event, ui) { 
    $("#amount").val("Rs." + ui.values[ 0 ] + " - Rs." + ui.values[ 1 ]);   
    var queryString="firstArg="+fArg+"&secondArg=sArg"; 
    window.location.href="/ControllerName/Classificate/?"+queryString 
} 

在相應的頁面控制器得到的URL參數和過程,幫助隊友的result.Hope .. :)

相關問題