这是我的代码:
<select style="background-color: #ffffa0" name="country" onChange="">
<option value="">---select country--</option>
<?php
$rows=DB::table('country')->get();
foreach ($rows as $row)
{
echo "<option value='$row->id'> $row->country </option>";
}
?>
</select>
如何从onChange调用控制器的功能?
答案 0 :(得分:0)
<html> <select style="background-color: #ffffa0" name="country" id="country">
<option value="">---select country--</option>
<?php
$rows=DB::table('country')->get();
foreach ($rows as $row)
{
echo "<option value='$row->id'> $row->country </option>";
}
?>
</select>
</html>
<script>
$(document).ready(function() {
$('#country').change(function(){
var country=$('#country').val();
$.ajax({
type: "post",
url: "AA/BB", // path to function
cache: false,
data: { country: country},
success: function(val){
try{
}catch(e) {
alert('Exception while request..');
}
},
error: function(){
alert('Error while request..');
}
});
});
});
</script>