最初の選択ボックスの選択に基づいて選択ボックスを設定しようとしていますが、それにはいくつか問題があります。単に何も起こらない。私が今まで持って何他に基づいて選択してください選択
(これは私のフッターにある):
<script src="./plugins/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select.category").change(function(){
var selectedCategory = $(".category option:selected").val();
$.ajax({
type: "POST",
url: "../inc/get_subcat.php",
data: { category : selectedCategory }
}).done(function(data){
$("#subcategory").html(data);
});
});
});
</script>
のdivを持つページが/pages/file.phpの場所にあります。
<div class="col-md-6">
<div class="form-group">
<label class="control-label">SubCategory</label>
<div id="subcategory"> </div>
</div> </div>
ないファイルこのエラーを修正しようとしている私を助けることができる誰かがある
<?php
include("config.php");
if(isset($_POST['category'])){
$cat = validar($_POST['category']);
$query = "SELECT id, subcategory FROM subcategories WHERE catid = ?";
#Prepare stmt or reports errors
($stmt = $mysqli->prepare($query)) or trigger_error($mysqli->error, E_USER_ERROR);
#Execute stmt or reports errors
$stmt->bind_param("i", $cat);
$stmt->execute() or trigger_error($stmt->error, E_USER_ERROR);
#Save data or reports errors
($stmt_result = $stmt->get_result()) or trigger_error($stmt->error, E_USER_ERROR);
#Check if are rows in query
if ($stmt_result->num_rows>0) {
echo "<select class='form-control' id='subcategory' name='subcategory'>";
# Save in $row_data[] all columns of query
while($row_data = $stmt_result->fetch_assoc()) {
# Action to do
echo "<option value='$row_data[id]'>$row_data[category]</option>";
}
echo "</select>";
}
$stmt->close();
}
?>
:クエリは、別のフォルダ(INC/get_subcat.php)にありますか?数時間試しても修正できません。
ありがとうございます!
編集: これは、すべての選択ボックスでHTMLコードです:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Category</label>
<select class='form-control' id='category' name='category'><option value='1'>Categoria 1</option><option value='2'>Categoria 2</option></select> </div>
</div>
<div class="col-md-6" id="subcategory">
</div>
</div>
あなたの '$ _POST' URLは機能しますか?あなたがそれに行くとき、または郵便配達でそれをテストするとき、それは何かをロードするか? AJAXリクエストは処理されますか?ブラウザツールを使用して、問題の場所を特定できるように要求が正常に処理されていることを確認します。 – kchason
このメソッドは 'validar()'を何としますか?エラー報告は何を返すのですか? –
エラーは報告されていません。 SQLインジェクションを避けるために、 "validar"は文字列をエスケープするだけです。スクリプトが呼び出されていないようです。私は何の誤りもありません。私がページ "get_subcat"に行き、$ catの値を定義すると、正しい値が削除されます。 – Tiago