简体   繁体   中英

Ajax to call external .php AND script on click?

I'm trying to make ajax to call an external php site (imageslider.php) and an additional script when clicking a menu item (.imageslider). Calling the .php works perfectly, but the script (js-image-slider.js) already fires up when starting the main page! And since I have like 7 menu items, each with different scripts, I'd like to have them loaded with $.getscript instead! Anyone knows what I'm doing wrong?

 <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');

Add null as second argument

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM