2016-08-02 84 views
0

我有一個jQuery加載函數的問題。 我也查了這篇文章,但它並沒有幫助我: Jquery load doesn't workjQuery加載+ Thymeleaf

這是負載的功能:

function loadMore(eventId) { 
    swal("Loading More"); 
    $.ajax({ 
     type: "GET", 
     url: "/event/detail/"+eventId+"/more", 
     datatype : "html", 
     success: function(html) { 
      console.log(html); 
      swal("Check console log"); 
      $("#detail-item.comments-bar.tag-fixed").load(html); 
      } 
    }); 
} 

,這是HTML:

<div class="detail-item comments-bar tag-fixed" th:fragment="commentsMore"> 
    <ul class="comments-list" > 
     <li> 
     <div class="content"> 
      <p th:unless="${!comments.content.isEmpty()}" >No comments. You can be the first one!</p> 
      <p sec:authorize="isAnonymous()">You are not logged in! Please log in to start commenting :)</p> 
     </div> 
    </li> 
    </ul> 
<a class="border-btn btn more" th:if="${!comments.content.isEmpty()}" th:onclick="'loadMore(\'' + ${event.eventId} +'\')'">Load previous comments</a> 
</div> 

控制器函數返回正確的HTML,因爲我將它記錄到控制檯。但是,沒有什麼事情真的發生,它不會刷新,也不會改變。

有什麼建議嗎?

回答

2

,我可以看到詳細的項目是一類,而不是一個ID,所以這一個

$(".detail-item.comments-bar.tag-fixed").load(html); 

希望替換此行代碼

$("#detail-item.comments-bar.tag-fixed").load(html); 

這有助於

+0

感謝有效! –

+0

完美!很高興爲你工作! –