Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to reload a separate template via Ajax?


Go to End


4 Posts   1628 Views

Avatar
Romano

Community Member, 13 Posts

12 April 2011 at 1:18am

Hello! I have a template in Include folder, like this:

<div id="mytemplate">
 	<% control MyControl(5) %>	  
  		$Content
   	<% end_control %>
</div>

How I can change dynamically the value of a parameter for MyControl (e.g. 5 to 10) and reload only this template without reload the site?

Such as: onClick="javascript:function(paramvalue);"

Thanks.

Avatar
swaiba

Forum Moderator, 1899 Posts

12 April 2011 at 1:59am

Edited: 12/04/2011 2:00am

well you could render your template independently with...
Controller...

function MyAJAX() {
Session::set('MyControlcount',Convert::raw2xml($_POST['PostedValue])); 
return $this->renderWith('IncludeTemplate');
}

...

function MyControl() {
$iCount = Session::get('MyControlcount');
if (empty($iCount)) $iCount=5;//defualt
//do and return stuff
}

template...

<div id="mytemplate"> 
   <% control MyControl() %>    
      $Content 
   <% end_control %> 
</div>

Avatar
Romano

Community Member, 13 Posts

12 April 2011 at 10:33pm

Edited: 12/04/2011 11:25pm

Thank you! Last question. How I can set $_POST['PostedValue'] via Ajax without receiving page?

Avatar
Romano

Community Member, 13 Posts

12 April 2011 at 11:18pm

Edited: 12/04/2011 11:25pm

Solved! I Must have been use method GET ($_GET['PostedValue']).