我正在尝试从现在有效的数据库中获取选项,但如果不提交<form>
<label for="NomEns">Choisir un enseignant: </label>
<select name="dd1" id="combo" class="form-control">
<option value="" <?php if(!isset($_POST['NomEns']) || (isset($_POST['NomEns']) && empty($_POST['NomEns']))) { ?>selected<?php } ?>>--Select--</option>
<?php while($row = $result->fetch_assoc()) { ?>
<option value="<?php echo $row['NomEns']; ?>" <?php if(isset($_POST['NomEns']) && $_POST['NomEns'] == $row['NomEns']) { ?>selected<?php } ?>><?php echo $row['NomEns']; ?></option>
<?php } ?>
</select>
答案 0 :(得分:0)
您需要使用onchange
事件
$('select').on('change', function() {
var value= this.value ;
$.ajax({
url:'action.php',
type:'POST',
data: {
'value':value
},
success: function(data) {
alert(data);
}
});
})
并制作档案action.php
if(isset($_POST['value'])) {
$username = $_POST['value'];
//your database query
$query=something;
if ($query) {
echo 'success';
}
else {
echo 'something went wrong';
}
}