Slim ajax- what to put in tht return


#1

hi i do a ajax script this is my controller:

public function newajax($request, $response){

 $articles = Article::find(1);

    $comment = new Comment;
    $comment->body = $request->getParam('body');
    $comment->user()->associate($this->auth->user());
    $articles->comments()->save($comment);

return $this->view->render($response,'home.html',compact('comment'));

}

and this is my HTML:

<h1><div id="text"></div></h1> <script> $("button").click(function(){ $("input").keyup(function(){ var body = $("input").val(); $.post("{{ path_for('newajax') }}",{ body : body },function(data){ $("test").html }); }); }); </script>
what i need to put in the return controller to stay in the same page and show the new comment in <h1> tag

thanku


#2

You can use knockout (http://knockoutjs.com/) to communicate from Slim to items on your webpage.
You can do what you want (replace a text within tags), or make a list that is filled with a json response from Slim.

Don’t try to invent the wheel :wink:
Knockout has good help to start with and is very easy to implement.