Quantcast

How to dynamically update one page with fragments using links?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to dynamically update one page with fragments using links?

Emina
How to dynamically update one page with fragments using links without refreshing the page?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to dynamically update one page with fragments using links?

migueldeblas
If you use spring mvc you must use a controller method that return a fragment and via jquery update the page.

 @RequestMapping(value = "/{id}", method = RequestMethod.GET)
 public String detailRefresh(@PathVariable long id, Model model) {

 T element = service.findOne(id);

 return "/frag_form :: ELEMENT";   // fragment
 }

jquery:

$(#myID).load(url);   // funtion that update via url from controller.

html template/jquery:
<html>
 <body>
   <div id="myID" th:replace="ELEMENT"></div> // <-- updateable
 </body>
</html>

see:
http://forum.thymeleaf.org/how-to-refresh-a-part-of-html-page-eg-a-div-td4027601.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to dynamically update one page with fragments using links?

Emina
No i am not using spring mvc. I am using a restcontroller for my restservices and jpa for database and a controller for views where I do all the server requestmappings. In resources I have made multiple fragments(.html not jsp) for different parts of the site and would like to only use one index.html that changes only one empty content div depending on what link is clicked. All the fragments are currently data-th-fragment and in the index file the content div has data-th-replace.
Also since everything is in fragments some of my team members have been complaining that their jquery is not working. The js script tag is located at the end of the index.html. Any suggestions if I have to place the same js script tag in the fragments as well?
Loading...