2012-07-21 32 views
0

-使用jQuery的AJAX上的Javascript

我該如何處理它,以便在Ajax調用後使用Javascript?

在我的頁面(wordpress) - 我有首頁上的所有帖子。我已經建立了與用戶可以過濾後具體的東西的職位filtersystem - 如「最新,最看,突出了」

我使用此功能下,使該過濾器的工作:

<script type="text/javascript"> 
    $(document).ready(function(){ 
    $.ajaxSetup({cache:false}); 
    $("#new").click(function(){ 

     var post_id = $(this).attr("rel") 
     $(".postbox_wrapper").html('<span class="filter_posts"> 
<img src="<?php bloginfo ('template_directory'); ?>/images/287.gif"></span>'); 
     $(".postbox_wrapper").load(jQuery(this).attr("href") + " .postbox_wrapper") 
     return false; 
    }); 
}); 

的visitior點擊「new」按鈕並過濾帖子 - 只顯示最新的帖子。但是我使用Javascript來進行disqus,惰性圖像加載器等等這些JS文件不會被加載到過濾後的帖子上。 (taxonomy.php)

這裏是例如一個JS文件,這將是neccessary使延遲加載器可供篩選的文章:

http://myurl/../plugins/bj-lazy-load/js/bjll.min.js?ver=0.4.0 

的問題是:我如何才能知道在上面的功能,也使用JS腳本在新加載的「過濾「頁面。

這是一個有點像這樣:Use Ajax() function in Jquery to load PART of an external page into div

,但我沒有得到它的工作....

非常感謝!

+0

你能改一下你的問題(更精確地)?我沒有得到你想要達到的目標。 – 2012-07-21 13:28:16

+0

我添加了一些更多細節。 – ad2003 2012-07-21 14:26:45

回答

0

我不知道我理解你的問題。 你是否正在加載一個特定的內容在一個div後加載腳本?

如果是試試這個:

$(function(){ 
    $.ajaxSetup({cache:false}); 

    $("#new").click(function(){ 
     var $this = $(this); 
     var $PostboxWrapper = $(".postbox_wrapper"); 

     var post_id = $this.attr("rel") 

     //I think you want load something like a loading .gif in taht point. Right? 
     $PostboxWrapper.html(
      "<span class='filter_posts'>" + 
      " <img src='<?php bloginfo ('template_directory'); ?>/images/287.gif'>" + 
      "</span>" 
     ); 

     $(".postbox_wrapper").load(jQuery(this).attr("href"), function() 
     { 
      $.getScript(
       "http://yourUrl/../plugins/bj-lazy-load/js/bjll.min.js?ver=0.4.0", 
       function(data, textStatus, jqxhr) { 
        console.log('Load was performed.'); 
       } 
      ); 
     }) 
     return false; 
    }); 
}); 
+0

嗨豪爾赫 - 感謝您的回覆!對,就是這樣。我嘗試將js加載到ajax加載的頁面中。我正在嘗試你的代碼 - 但它將整個頁面加載到div – ad2003 2012-07-21 13:47:16

+0

js應該只傳遞給新加載的頁面...我想這個getScript的東西是正確的。但它不起作用 – ad2003 2012-07-21 14:15:22