假設我有我的網頁一個簡單的形式是這樣的:如何使用JQuery提交我的GET表單時更改查詢字符串?
<form action="/properties/search" method="GET" id="form_search">
<p>
<label for="price">Min price:</label>
<input type="text" name="min_price" id="min_price">
</p>
<p>
<label for="price">Max price:</label>
<input type="text" name="max_price" id="max_price">
</p>
<p>
<input type="submit">
</p>
</form>
當我提交我的形式,我有以下網址:
http://.../properties/search?min_price=100000&max_price=200000
我想改變這個網址有:
http://.../properties/search?price=100000,200000
爲了做到這一點,我使用jQuery和JQuery querystring plugin:
$(document).ready(function() {
$("#form_search").submit(function() {
var querystring = rewrite_interval_qstring();
// querystring equals "?price=100000,200000" -> exactly what I want !
// ???
});
});
如何更改(評論「???」)提交網址?我已經單獨測試了以下說明,但不起作用。
window.location = querystring;
window.location.href = querystring;
window.location.search = querystring;