2013-06-26 63 views
1
http://example.com/bills.php?sort=highest 
http://example.com/bills.php?sort=alpha 
http://example.com/bills.php?sort=lowest 

所以網址aboves排序最高,字母和最低。他們使用$ _GET方法並使用表單。我想知道是否有一種方法來提交表單/獲取$ _GET數據而不更改網址?

<form action="bills.php" method="get"> 
    <select onchange="this.form.submit();" name="sort" class="right sort"> 
     <option>What would you like to sort by?</option> 
     <option value="highest" <?php if(isset($_GET['sort']) && $_GET['sort'] == 'highest'){?> selected="selected" <?php } ?>>Highest to Lowest</option> 
     <option value="lowest" <?php if(isset($_GET['sort'])&& $_GET['sort'] == 'lowest'){?> selected="selected" <?php } ?>>Lowest to Highest</option> 
     <option value="alpha" <?php if(isset($_GET['sort'])&& $_GET['sort'] == 'alpha'){?> selected="selected" <?php } ?>>Alphabetically</option> 
    </select> 
</form> 

上面是我可以提交新的排序請求的代碼。

我想提出我的網址留在example.com/bills.php那會是可能的嗎?

這將是可能改寫使用.htaccess中的網址是什麼?我已經嘗試了URL重寫方法,它允許我去參觀http://example.com/bills/alpha,它工作正常,但是當我選擇一個新的查詢,它變成http://example.com/bills/bills/?sort=alpha

這裏是我的.htaccess

RewriteEngine On 
RewriteBase/
RewriteRule ^bills/(.*)$ /bills.php?id=$1 
+2

請使用帖子代替嗎? – HamZa

+2

使用形式方法後,保持值在一個隱藏字段相同的形式 – ejo

+0

下不使用後*是否有你的任何理由*? – Novocaine

回答

4

使用AJAX,就可以解決這個問題。無需在.htaccess中進行任何更改。以下是可以幫助您的代碼:

$(".right").change(function(){ 
    $.get("YourFile.php",{"sort":$(this).val()},function(res){ 
     alert(res); 
    }); 
});