目前,我有一個選擇標籤,每次用戶單擊該特定選擇標籤時,我都想通過 AJAX 調用填充該標籤。為此,我正在執行以下操作:
查看類:
<label class="control-labels ">Property</label>
<select name="property" class="form-control select2 selectsearch" <?php echo (isset($read) ? $read:''); ?> required>
</select>
Ajax 請求:
$(document).ready(function(){
$("#property").click(function(){
var post_url = 'listings/getonClick'
$.ajax({
type: "POST",
url: post_url,
data : { "hid" : $(this).val() },
success: function(response){
$.each(response, function(value, key) {
$("#property").append("<option id="+value.id+">"+value.name+"</option>");
})
}
});
});
控制器類:
function getonClick(){
$modelList = $this->listings_model->getProperties();
echo(json_encode($modelList));
}
型號分類:
function getProperties(){
$this->db->select("id,name");
$this->db->from("crm_project_properties");
$query = $this->db->get();
return $query->result_array() ;
}
但是這樣做之後,在單擊它之前或什至之後,我都無法在我的選擇標籤中獲取任何數據
ypu 可以試試 .on("click") 嗎?它過去對我有用
$(document).ready(function () {
$("#property").on("click", '*:not(a)', function() {
var post_url = 'listings/getonClick'
$.ajax({
type: "POST",
url: post_url,
data : { "hid" : $(this).val() },
success: function(response){
$.each(response, function(value, key) {
$("#property").append("<option id="+value.id+">"+value.name+"</option>");
})
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句