Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » How to reload a separate template via Ajax?

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

Page: 1
Go to End
Author Topic: 764 Views
  • Romano
    Avatar
    Community Member
    13 Posts

    How to reload a separate template via Ajax? Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: How to reload a separate template via Ajax? Link to this post

    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>

  • Romano
    Avatar
    Community Member
    13 Posts

    Re: How to reload a separate template via Ajax? Link to this post

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

  • Romano
    Avatar
    Community Member
    13 Posts

    Re: How to reload a separate template via Ajax? Link to this post

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

    764 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.