How do I perform/work the call through the AJAX url?

Asked

Viewed 64 times

1

To put it in context:

There is a remote directory, clearing-dit\logs, which has a number of logs (portal.log, test.log, ...). This directory, is mapped to an HTML page, where all of its .log's are displayed. Once one of them is clicked, its respective content is displayed.

inserir a descrição da imagem aqui

This content is loaded through the HTML/Thymeleaf page, which calls the content a log.java.

<p th:utext="${log.content}">Log content</p>

The need arose to make this content continue to be displayed (its updates) every 5 seconds, in real time and without having to update the entire page, only updating where the content is. I have been researching and I saw that I can/should do it through an AJAX, but his concept is somewhat vague for me.

My doubt:

How do I perform/work the call through the AJAX url? I know that in AJAX there are two type fields -> POST/GET and the url -> (?), but I cannot understand how this "crossover" works, because, in theory, if it were possible to call the method that displays the current content:

@RequestMapping(value = "/log", method = RequestMethod.POST)
    public String logContent(@Valid Log log, BindingResult bindingResult, Map<String, Object> model) {
        if (log.getInitLine() == 0 && log.getFinalLine() == 0) {
            try {
                fileNumberLines(log);
                log.setContent(getLogContentByRange(0, log.getInitLine(), log.getFinalLine(), logsDir + "/" + log.getFilename()));
            } catch (IOException e) {
                logger.error(e.getMessage());
            }
        } else {
            log.setContent(getLogContentByRange(0, log.getInitLine(), log.getFinalLine(), logsDir + "/" + log.getFilename()));
        }

        model.put("path", logsDir);
        model.put("log", log);
        model.put("currentPage", "logs");
        model.put("root", root);

        return "log";
    }

Every five seconds, it would solve the problem.

  • In your case, a simple refresh of the page would not solve?

  • The idea was to refresh only in the <div> that the content is, precisely to prevent the whole page is updated. I didn’t mention it at all, I’ll edit it!

  • Cara take a look here to see if it helps you http://www.marcelustrojahn.com/2016/10/spring-boot-boote-thymeleaf-fragmentos-via-ajax/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.