【问题标题】:jQuery load + ThymeleafjQuery 加载 + Thymeleaf
【发布时间】:2016-08-02 16:57:22
【问题描述】:

我对 jQuery 加载函数有疑问。 我也检查了这篇文章,但它对我没有帮助: Jquery load doesn't work

这是加载函数:

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,因为我将其记录到控制台。但是视图中没有真正发生任何事情,它不会刷新,也不会改变。

有什么建议吗?

【问题讨论】:

    标签: javascript jquery spring spring-mvc thymeleaf


    【解决方案1】:

    我可以看到detail-item是一个类而不是一个id,所以替换这行代码

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

    这个

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2019-10-05
      • 2022-12-19
      • 1970-01-01
      • 2021-04-05
      • 2018-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      相关资源
      最近更新 更多