通过AJAX GET调用加载后,jQuery脚本无法加载

时间:2012-12-11 13:25:55

标签: jquery ajax web

在从jQuery AJAX GET加载文件后尝试解决如何加载jQuery脚本时遇到一些困难。

此代码绑定到div id为navhome:

$('#navhome').live('click',getHome);

以下代码是从服务器获取文件的内容。

function getHome() {    
$('#pagecontent').fadeOut('fast', function() {
    $.ajax({
    type: "GET",
    url: "../../pages/home.php",
    success: postToPage});
});}

此代码将其放在页面上:

function postToPage(data, status) { 
$('#pagecontent').html(data);}

我想要发生的是在加载文件时运行滑块插件,但是我很难理解我需要做什么才能让它运行。

我有上面的功能,我为我的Minecraft服务器制作了一个小网站,它可以在http://www.chernobylserver.com找到 。当您单击“成员”页面时,它会使用上面的内容加载新内容,但是当我单击“主页”时,它不会重新加载滑块脚本。

如果你能够指出我正确的方向,我会永远感激你。现在已经让我感到不安了一会儿。这对我来说都是新的领域。

感谢您花时间阅读本文,我真的很感激。 : - )

Callum Kerr

1 个答案:

答案 0 :(得分:1)

只需将你的nivoslider init转换为函数

 function startSlider() {
     jQuery('#slider').nivoSlider( [... options here ...] );
 }

并将其添加到postToPage();

   function postToPage(data, status) {  
     $('#ajaxcontent').html(data);
     $('#ajaxcontent').fadeIn('slow');
     $('#footerribbon').fadeIn('slow');
     startSlider();
   }

此外,快速提示:不要使用.live()。使用$.on()

相关问题