2016-09-29 16 views
0

觸發,只要我輸入我的家庭ID即可。它會加載記錄和輸入ID chli_hh_id也將被填充。並且如果輸入#cli_hh_id已填充。在href =」不被觸發。好心幫請..謝謝:)關於更改事件不會通過ajax php

這裏是我的輸入文本框。

    <input type="text" id = "hh_id" name = "hh_id" placeholder="Please enter Household ID" class = "form-control" href="<?=base_url('location/hh_members')?>"> 
       <input type="text" id = "cli_hh_id" name = "cli_hh_id" class = "form-control" href="<?=base_url('location/cli_hh')?>"> 

這裏是關於#hh_id我的js。這裏沒有任何問題。

$(document) 
.on('change', '#hh_id', function(){ 

    var hh_id = this.value; 
    $.ajax({ 
     url: $(this).attr('href') + '/' + hh_id, 
     dataType: 'json', 
     success:function(data){ 
      console.log(data); 
      var html = ""; 
      for (var i = 0; i < data.length; i++) { 
       html += "<option data-cli_hh_id = '"+data[i].cli_hh_id+"' data-entry_id = '"+data[i].entry_id+"' data-my_name = '"+data[i].my_name+"' data-sex = '"+data[i].sex+"' data-brgy = '"+data[i].brgy+"' data-muncity = '"+data[i].muncity+"' data-province = '"+data[i].province+"' data-region = '"+data[i].region+"' value='"+data[i].value+"'>"+data[i].value+"</option>"; 
      }; 
      $('#full_name').html(html); 
     } 
    }); 
}); 

這是我遇到我的問題,這是不被觸發時,它有它的價值。:(

$(document) 
.on('change', '#cli_hh_id', function(){ 
alert('Is this loading?'); 
    var cli_hh_id = this.value; 
    $.ajax({ 
     url: $(this).attr('href') + '/' + cli_hh_id, 
     dataType: 'json', 
     success:function(data){ 
      console.log(data); 
      var html = ""; 
      for (var i = 0; i < data.length; i++) { 
       html += "<p>"+ data[i].key + " " + data[i].value+"</p>"; 
      }; 
      $('#cli_household').html(html); 
     } 
    }); 
}); 

回答

0

變更低於[非強制性]如前所述行

$('#hh_id').change(function() { ... }); 

$('#cli_hh_id').change(function() { ... }); 

然而,這一事件只會當選擇已經失去焦點,所以你需要點擊其他地方來觸發該功能火災。

或者,您可以使用其他jQuery events如鍵控,keydown或按鍵 - 取決於您想要的確切效果。