[英]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). 我正在尝试使ajax在单击菜单项(.imageslider)时调用外部php网站(imageslider.php)和其他脚本。 Calling the .php works perfectly, but the script (js-image-slider.js) already fires up when starting the main page! 调用.php效果很好,但是启动主页时脚本(js-image-slider.js)已经启动! And since I have like 7 menu items, each with different scripts, I'd like to have them loaded with $.getscript instead! 并且由于我喜欢7个菜单项,每个菜单项具有不同的脚本,因此我想将它们加载为$ .getscript! 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 将null添加为第二个参数
$('.imageslider').on('click', null, function(){
// code
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.