jquery Ajax只调用第一次而不是第二次

时间:2016-09-21 23:10:04

标签: jquery ajax

我对jquery和ajax很新。我想要做的是在表单中有级联选择字段。使用ajax调用的第一个相关选择字段正常工作,但第二个不执行任何操作。任何人都可以解释为什么会这样吗?我认为这与缺乏基本理解有关,并为无知道歉。

由于 埃林

<script type='text/javascript'>
  jQuery(document).ready(function(){                
    // when any option from country list is selected

    jQuery("select[name='market']").change(function(){    

        // path of ajax-loader gif image
        var ajaxLoader = "<img src='ajax-loader.gif' alt='loading...' />";

        // get the selected option value of country
        var optionValue = jQuery("select[name='market']").val();        

        jQuery("#dateAjax")
            .html(ajaxLoader)
            .load('data.php', "market="+optionValue+"&status=1", function(response){
                if(response) {
                    jQuery("#dateAjax").css('display', '');
                } else {
                    jQuery("#dateAjax").css('display', 'none');
                }
        });            
    });
    jQuery("select[name='marketdate']").change(function(){    

        // path of ajax-loader gif image
        var ajaxLoader = "<img src='ajax-loader.gif' alt='loading...' />";

        // get the selected option value of country
        var optionValue = jQuery("select[name='marketdate']").val();        

        jQuery("#timeAjax")
            .html(ajaxLoader)
            .load('datedata.php', "marketdate="+optionValue+"&status=1", function(response){
                if(response) {
                    jQuery("#timeAjax").css('display', '');
                } else {
                    jQuery("#timeAjax").css('display', 'none');
                }
            });            
        });

        jQuery(document.body).on('change','#marketdate',function(){
            // path of ajax-loader gif image
            var ajaxLoader = "<img src='ajax-loader.gif' alt='loading...' />";

            // get the selected option value of country
            var optionValue = jQuery("select[name='marketdate']").val();        

            jQuery("#timeAjax")
                .html(ajaxLoader)
                .load('datedata.php', "marketdate="+optionValue+"&status=1", function(response){
                    if(response) {
                        jQuery("#timeAjax").css('display', '');
                    } else {
                        jQuery("#timeAjax").css('display', 'none');
                    }
                });
        });
  });
</script>

0 个答案:

没有答案
相关问题