提问人:Maneesh Kumar 提问时间:11/1/2023 最后编辑:RiggsFollyManeesh Kumar 更新时间:11/1/2023 访问量:29
使用 jQuery AJAX 发送多个数据参数
Send multiple data parameters with jQuery AJAX
问:
在我的注册表中,种姓选项应根据“母语”和“宗教”显示。有人可以帮助我这样做吗?
<form>
<script type="text/javascript">
function getCaste(){
var m = document.getElementByID('mToungId').value;
var r = document.getElementByID('relId').value;
$.ajax({
type: "POST",
url: "getCaste.php",
data: {
mtId=m,
relg_id=r,
}
success:function(data){
$("#castId").html(data);
}
})
}
</script>
<!--Mother Tongue-->
<div class="form-floating mb-3">
<select name="mToungId" id="mToungId" class="form-control" onChange="getCaste();">
<option value disabled selected>Select Mother Tongue</option>
<?php
$mtquery = mysqli_query($stopu,
"select *
from mothertongue
where status = 'APPROVED'
order by mtongue_name asc");
while($mtresult=mysqli_fetch_array($mtquery)){
?>
<option value="<?php echo $mtresult["mtongue_id"]; ?>"><?php echo $mtresult["mtongue_name"]; ?></option>
<?php
}
?>
</select>
<label for="inputState">Mother Tongue</label>
</div>
<!--Relogion-->
<div class="form-floating mb-3">
<select name="relId" id="relId" class="form-control" onChange="getCaste(this.value);">
<option value disabled selected>Select Religion</option>
<?php
$relquery = mysqli_query($stopu,
"select *
from religion
where status = 'APPROVED'
order by religion_name asc");
while($relresult=mysqli_fetch_array($relquery)){
?>
<option value="<?php echo $relresult["religion_id"]; ?>"><?php echo $relresult["religion_name"]; ?></option>
<?php
}
?>
</select>
<label for="inputState">Religion</label>
</div>
<!--Caste-->
<div class="form-floating mb-3">
<select name="castId" id="castId" class="form-control">
<option value="">Select Religion First</option>
</select>
<label for="inputEmail">Caste</label>
</div>
</form>
getCaste.php
<?php
include_once('adithara.php');
if(!empty($_POST["relg_id"])){
$cstquery = mysqli_query($stopu,
"select *
from caste_view
where religion_id = '".$_POST["relg_id"]."'
and mtongue_id = '".$_POST["mtId"]."'
status = 'APPROVED'
order by caste_name asc");
?>
<option value disabled selected>Select Caste</option>
<?php
while($cstresult=mysqli_fetch_array($cstquery)){
?>
<option value="<?php echo $cstresult["caste_id"]; ?>"><?php echo $cstresult["caste_name"]; ?></option>
<?php
}
}
?>
我确定错误出在编码中。我想首先选择 Mother Toungue,然后选择 Religion,种姓应该根据这两个值从数据库中显示。
答: 暂无答案
评论
AND
"select * from caste_view
data: { mtId: m, relg_id: r }
MYSQLI_
PDO
'
O'Neal'