response only body elements

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

response only body elements

tsuyoshi
I want to use some of the response for ajax and pjax.
Do you have any good ideas?
Reply | Threaded
Open this post in threaded view
|

Re: response only body elements

Zemi
Administrator
You can use any client-side technologies, like ajax or pjax (I assume this is pjax), with Thymeleaf.

Could you elaborate your question a bit more?

We will be glad to help you.
Reply | Threaded
Open this post in threaded view
|

Re: response only body elements

tsuyoshi
Thank you, Zemi.

*JavaScript
$.get("/ajax/users", function(response) {
  $("#contents").html(response);
});

*Result
I just added pure html from thymeleaf.
It would become a invalid HTML.
<div id="contents">
  <!DOCTYPE html>
  <html lang="ja" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head>
    </head>
    <body>
      <div class="users">...</div>
    </body>
  </html>
</div>

I want a result like this (only body elements), Because this is a valid HTML.

<div id="contents">
  <div class="users">...</div>
</div>

I want to be able by thymeleaf.

thanks.
Reply | Threaded
Open this post in threaded view
|

Re: response only body elements

Zemi
Administrator
Ok, this is just a jQuery issue.

You could use the jQuery load() function instead of get().

With the load() function, you load some portion of the target page.

You should modify your javascript code like:

   $('#contents').load('/ajax/users #result');

and the page '/ajax/users' mush have an id "result":

   <!DOCTYPE html>
   <html lang="ja" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head>
    </head>
    <body>
      <div id="result" class="users">...</div>
      </body>
    </html>

Reply | Threaded
Open this post in threaded view
|

Re: response only body elements

tsuyoshi
Thanks Zemi. I'll try it.

However, it doesn't use some jQuery plugin.
I hope to support partial response in the future:)