Ajax 在单击时调用外部.php和脚本


Ajax to call external .php AND script on click?

我正在尝试使ajax在单击菜单项(.imageslider)时调用外部php站点(imageslider.php)和附加脚本。调用.php工作得很好,但是脚本(js-image-slider.js)在启动主页时已经启动了!由于我有 7 个菜单项,每个菜单项都有不同的脚本,我希望用 $.getscript 加载它们!有人知道我做错了什么吗?

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>jQuery(document).ready(function($) {
$('.imageslider').on('click', function() {
    var href = $(this).attr('href');
    if ($('#ajax').is(':visible')) {
        $('#ajax').css({ display:'block' }).animate({ height:'0' }).empty();
    }
    $('#ajax').css({ display:'block' }).animate({ height:'2000px' },function() {
        $('#loader').css({ border:'none', position:'relative', top:'24px', left:'48px', boxShadow:'none' }); 
        $('#ajax').load('imageslider.php ' + href, function() {
            $('#ajax').hide().fadeIn('slow').colorFade({ 'fadeColor': '#0e0e0e'});
        });
    });
}).click(); // calls imageslider initially without clicking it, because it's the main page
});$.getScript('/js/js-image-slider.js');

添加 null 作为第二个参数

$('.imageslider').on('click', null, function(){
// code
});