monal86
monal86

Reputation: 463

Refresh Only template Grails

I have a list.gsp which loads a template . Actually the template contains which loads the data from the domain class. Every 10 seconds I want to refresh the template only, so that it gets latest data from the db. How can i do this?

Upvotes: 1

Views: 1348

Answers (1)

Gregg
Gregg

Reputation: 35904

There are several ways to solve this but all of them require Ajax. I'll give one example:

Suppose the following HTML:

<div class="content">

  ... other content here

  <div id="template">
     <g:render template="someTemplate" ... />
  </div>

  ... other content here

</div>

Then this javascript:

setInterval(refreshTemplateEveryTenSeconds, 10000);

function refreshTemplateEveryTenSeconds() {
   $('#template').load("/some/server/resource"); 
}

See the jquery load docs for more info on this.

Obviously, if you're not using jQuery then modify to do the ajax call as your technology would suggest. But this gives you a general idea of how you might approach the problem.

Upvotes: 4

Related Questions