私はデータを動的に取得して別のページに送信するシンプルなフォームのコードを用意しています。そのデータを使用して、私のページにいくつかのdivが表示されます。 AJAXを使わずにチェックするとdivを返す。しかし、今ではAJAXをいくつか適用していますが、動作しません。どんな提案もお願いします。AJAX jqueryが応答せずdivを表示しています
AJAX
$("document").ready(function() {
$("#search_keyword").on("submit", function (e) {
e.preventDefault();
$.post("keyword_search.php?query="+encodeURIComponent($("#keyword").val())+"category="+encodeURIComponent($("#category").val())+"store="+encodeURIComponent($("#store").val()), function (data) {
var res = JSON.parse(data);
if (res.divs) {
$('#search_result').html("");
for (var i = 0; i < res.divs.length; i++) {
$('#search_result').append(res.divs[i]);
}
} else {
$('#search_result').html("No matched coupons found !");
}
});
});
});
フォームあなたはそれが実際に提出することができるようにbutton
からsubmit
タイプに変更する必要が
<form class="form-horizontal select-search" id="search_keyword" method="post">
<label class="control-label ">Keyword</label>
<input class="form-control" id="keyword" name="keyword" type="text">
<!-- Select Category -->
<label class="control-label " for="category">Select category</label>
<select class="category" id="category" name="category">
<?php
$sm=mysqli_query($con,"select * from categories ");
while ($row1 = mysqli_fetch_array($sm,MYSQLI_ASSOC)){
$cat_id = $row1['cat_id'];
$name = $row1['cat_name'];
echo '<option value="' . $cat_id . '">' . $name . '</option>';
}
?>
</select>
<label class="control-label " for="store">Select a store</label>
<select class="storesname" id="store" name="store">
<option selected="selected">Select Stores</option>
</select>
<button id="search_btn" name="search_btn" class="btn btn-danger">Search coupons</button>
</form>
<div id="search_result"> </div>
変更ボタンを助けるかもしれない「#search_btn」に「クリック」と「#search_keyword」に「送信」
を変更しました –
'
は依然として応答しません。私はそこにajax投稿に問題があると思う投稿 – tabia