我想检索与最后一个下拉列表“Provinsi”相关的下拉列表数据“kabupaten”,但我不能,这里我的代码'index.html
"android": {
"release": {
"keystore": "my-release-key.keystore",
"storePassword": "nidhin",
"alias": "nidhin",
"password": "nidhin",
"keystoreType": ""
}
}
在index.html中,我们从用户那里获取数据并将其解析为get_state.php 在这里我的get_state.php
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
$query ="SELECT * FROM provinsi";
$results = $db_handle->runQuery($query);
?>
<html>
<head>
<TITLE>jQuery Dependent DropDown List - Countries and States</TITLE>
<head>
<style>
body{width:610px;}
.frmDronpDown {border: 1px solid #F0F0F0;background- color:#C8EEFD;margin: 2px 0px;padding:40px;}
.demoInputBox {padding: 10px;border: #F0F0F0 1px solid;border-radius: 4px;background-color: #FFF;width: 50%;}
.row{padding-bottom:15px;}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
function getState(val) {
$.ajax({
type: "POST",
url: "get_state.php",
data:'idprov='+val,
success: function(data){
$("#kabupaten-list").html(data);
}
});
}
function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
</script>
</head>
<body>
<div class="frmDronpDown">
<div class="row">
<label>Provinsi:</label><br/>
<select name="provinsi" id="provinsi-list" class="demoInputBox" onChange="getState(this.value);">
<option value="">Select Provinsi</option>
<?php
foreach($results as $provinsi) {
?>
<option value="<?php echo $provinsi["id_prov"]; ?>"><?php echo $provinsi["provinsi"]; ?></option>
<?php
}
?>
</select>
</div>
<div class="row">
<label>State:</label><br/>
<select name="kabupaten" id="kabupaten-list" class="demoInputBox">
<option value="">Select State</option>
</select>
</div>
</div>
</body>
答案 0 :(得分:1)
我不使用jQuery所以我可能错了,但我相信你在ajax POST中发送的数据需要是对象文字表示法,即{param:value}
- 所以更像这样: -
function getState(val) {
$.ajax({
type:"POST",
url:"get_state.php",
data:{ 'idprov':val },
success: function( data ){
$("#kabupaten-list").html( data );
}
});
}