m.aibin m.aibin - 1 year ago 195
jQuery Question

jQuery load + Thymeleaf

I have a problem with jQuery load function.
I checked also this article, but it didn't help me:
Jquery load doesn't work

This is the load function:

function loadMore(eventId) {
swal("Loading More");
type: "GET",
url: "/event/detail/"+eventId+"/more",
datatype : "html",
success: function(html) {
swal("Check console log");

and this is HTML:

<div class="detail-item comments-bar tag-fixed" th:fragment="commentsMore">
<ul class="comments-list" >
<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>
<a class="border-btn btn more" th:if="${!comments.content.isEmpty()}" th:onclick="'loadMore(\'' + ${event.eventId} +'\')'">Load previous comments</a>

The controller function returns HTML correctly, as I am logging this to the console. But nothing really happens in the view, it does not refresh, it does not change.

Any suggestions?

Answer Source

As I can see the detail-item is a class and not an id, so replace this line of code


with this one


Hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download