weixin_33730836 2016-05-10 10:48 采纳率: 0%
浏览 17

如何在AJAX中使用AJAX?

I am using the following JavaScript to get the HTML.

$('#myHref').change(function() {
    var value = $('#myHref').val();
    $.get('get_project.php',{id:value},function(data) { 
        $('#projectDetail').html(data);
        $('#projectDetail').fadeIn('slow');
    }); 
}); 

I use some html in get_project.php as follow:

<select name="sn_id" id="sn_id" >
    <option>Data1</option>
    <option>Data2</option>
    .....
</select> 

I want to select menu and get returned on the basis of it. So again I add the following JavaScript to get value according to selected sn_id:

$('#sn_id').change(function() {
    var value = $('#sn_id').val();
    $.get('calculate_invest.php',{id:value},function(data) { 
        $('#show_me').html(data); 
    }); 
}); 
  • 写回答

1条回答 默认 最新

  • csdnceshi62 2016-05-10 12:24
    关注

    you are dynamically adding your "select" , then you need to add the event in the document, like this:

    $(document).on('change','#sn_id', function() {
        var value = $('#sn_id').val();
        $.get('calculate_invest.php',{id:value},function(data) { 
            $('#show_me').html(data); 
        }); 
    }); 
    
    评论

报告相同问题?