我試圖做GET使用jQuery AJAX功能的形式要求,但問題是,我沒有看到在URL中的參數:AJAX GET請求不顯示PARAMS在URL
這裏是代碼:
<form id="search_form" method="GET" action="">
<input id="seach_input" type="text" name="q">
<button id="search_btn" class="btn btn-warning" type="submit">Search</button>
</form>
這裏的Javascript代碼:
$("#search_form").on('submit', function(e) {
$.ajax({
url: "index.html",
type: "GET",
data: {name: "hello"},
success: function() {
console.log("success);
}
});
e.preventDefault();
});
我提交後,我想要的網址看起來像這樣:
http://localhost/search.html?q=value
我知道e.preventDefault();是參數沒有出現在URL中的原因,但我需要這樣做,而不需要刷新頁面,並且同時我希望在執行GET請求時看到參數。
請幫忙!
謝謝。
你試過'返回FALSE'代替的preventDefault ?; –