在不刷新页面的情况下更新thymeleaf中的表

时间:2019-02-20 16:53:32

标签: javascript spring thymeleaf

JS代码:

<script type="text/javascript" th:inline="javascript">
    var senderLogin = [[${senderLogin}]]
    var recipientLogin = [[${recipientLogin}]]
    function CheckAndGetMessage() {
        $.ajax({
            type : "GET",
            url: '/get_updated_dialog',
            data: {'senderLogin':senderLogin, 'recipientLogin':recipientLogin },
            success: function (messageList) {
                document.getElementById("messageList_local").value = messageList;
                $('#message_table').DataTable().ajax.reload();
                return;
            }

        });
    };

    setInterval(CheckAndGetMessage,1000);

Java代码:

@RequestMapping(value = "/get_updated_dialog",method = RequestMethod.GET)
@ResponseBody
public List<Message>  getUpdatedDialog(Authentication authentication, @RequestParam("senderLogin") String  senderLogin, @RequestParam("recipientLogin") String  recipientLogin, Model model){
    List<Message> messageList = messageService.UpdatedDialogBetweenUsers( recipientLogin, senderLogin,authentication, model);
    return messageList; }

另一个Java代码:

model.addAttribute("messageList", messageList);

(属性是在函数中添加的,该函数返回带有表页面的视图)

我的桌子:

<div id="messageList_local" th:with="messageList_local=${messageList}">
    <table id="message_table" cellspacing="0" cellpadding="0">
            <span th:each="message : ${messageList}"> <!-- close tags and etc -->

我试图在JS中调用它:

                document.getElementById("messageList_local").value = messageList;
            $('#message_table').DataTable().ajax.reload();

但是我的桌子没有刷新。附言我检查了调试器,发现getUpdatedDialog返回包含更新消息的列表。

0 个答案:

没有答案