아약스를 사용하여 선택 상자를 수행하지만 첫 번째 선택 상자를 선택하면 두 번째 선택 상자에 값이 표시되지 않습니다. 어떻게 두 번째 선택 상자에 값을 표시 할 수 있습니까?다른 선택 상자 값에 따라 상자 선택 ph
의 index.php (jQuery를)
$(document).ready(function(){
$('#brand').on('change',function(){
var brand = $(this).val();
if(brand){
$.ajax({
type:'POST',
url:'ajax_city.php',
data:'brand='+brand,
success:function(html){
$('#outlet').html(html);
}
});
}else{
$('#outlet').html('<option value="">Select OUTLET first</option>');
}
});
});
의 index.php (HTML/PHP)
<select class="brand" style="width:200px" id="brand" name="brand" >
<?php $i = 0;
while (!$br->EOF) {
$fv = $br->Fields("mBrand");
$name = $fv->value;
echo '<option value="' . trim($name) . '"><b>' . $name . '</b></option>';
$br->MoveNext();
}
?>
</select>
<input type="hidden" name="loc" id="loc">
</td>
</div>
<li class="form-line" id="id_19">
<label class="form-label-left" id="label_19" for="input_19"> Outlet </label>
<div id="cid_20" class="form-input">
<br><br>
<select class="outlet" name="outlet" id="outlet" style="width:200px" >
<option value="">--Select outlet--</option>
</select>
ajax_city.php :
if(isset($_POST["brand"])&&!empty($_POST["brand"]))
{
$brand=$_POST['brand'];
$rb = $itdeptconn->Execute("SELECT DISTINCT mOutlet FROM [IT_Dept].[dbo].[mstOutlet] WHERE mBrand='".$brand."'");
//$sql=mysql_query("select b.id,b.data from data_parent a,data b where b.id=a.did and parent='$id'");
echo '<option value="">Select Outlet</option>';
while (!$rb->EOF) {
$fv = $rb->Fields("mOutlet");
$name = $fv->value;
echo '<option value="' . trim($name) . '"><b>' . $name . '</b></option>';
$rb->MoveNext();
}
}
?>
모든 콘솔 오류가? – Rasclatt
아약스에서'data : { "brand": brand}, ' – Rasclatt
@Rasclatt 오류 표시 안 함. – Jazlyn