Javascript reload after rendering your thymeleaf fragment

I have javascript files defined in <head>both my layout decorator template and my individual pages that are decorated. When I update a thimeleaf fragment on one of my pages, the javascript defined in the title of the parent page no longer works. Is there a standard way to “update” these js files?

Thank.

Additional explanations:

I have a form submitted by an ajax call that updates a table on a page. I have a Jquery onClick function targeting a button in an updated table. Javascript doesn't seem to be able to bind to returned elements in the updated part of the page. I select the element class and see that the selection works before rendering the partial fragment.

+4
source share
2 answers

It’s not clear to me what you mean by

javascript defined in the header of the parent page no longer works.

The page was created on the server. Usually it contains javascript file urls

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

In this case, the "update" of javascript files can occur only in the client.

Check the html pages on the client. Are tags expected? Are there tags for all expected javascript files?

Using browser tools (such as Google Chrom developer tools) make sure all script files are uploaded.

If this does not help, it may be that the order of the script tags has changed between the first and second load. This may result in other javascript behavior being executed in the browser.

EDIT:

javascript dom.

JQuery .

dom , , , dom.

, .

"", .

JQuery, , , .

0

DOM .

, , , :

<button class="someclass">Button 1</button>

<script>
    var something = function() {
        // do something
    };
    $(".someclass").on("click", something);
</script>

DOM, click. , ajax, ( 2 ).

    $(".someclass").off("click");
    $(".someclass").on("click" , something);
0

All Articles