Thank you very much Thomas, got the response back properly with the html code, still getting some errors so gotta see what's wrong with that.
On Sep 14, 12:14 pm, Thomas Ploch <[email protected]> wrote: > erm, the same as you would set it to any other view: > > <?php > > function action() { > [...] > // inside your action > $myArray = array('tweet' => 'feep feep feep'); > // or $myArray = json_decode($yourJsonObject, true); > > // Set the variable just like any other var > $this->set(compact('myArray')); > > // This will render the element in '/views/elements/element.ctp' with > the data in $myArray > // So you can access $myArray in the element just like a normal > view var > $this->render('/elements/element'); > } > > Am 14.09.2011 18:06, schrieb 8vius: > > > > > > > > > And how can I pass an array into the view? I do it in other parts of > > my code just doing $this->render('element', $data) but it's giving me > > an error here > > > On Sep 14, 11:59 am, Thomas Ploch<[email protected]> wrote: > >> The RequestHandler Component is not doing any requests, it just verifies > >> that the current request indeed is an AJAX request, so you can check in > >> an action and i.e. render an element with an AJAX layout instead of > >> rendering the whole view. You can of course generate the HTML with > >> javascript using the returned JSON object > >> (http://api.jquery.com/jQuery.template). But in my oppinion it is way > >> easier to do the data handling in the action, and just render the > >> element's HTML with $this->render() and use that in the success callback > >> of the jQuery $.post method, appending the rendered HTML into a DOM node. > > >> Am 14.09.2011 17:51, schrieb 8vius: > > >>> hmmm I don't use the request handler to do my ajax requests, I just > >>> echo out the response, would that work ? doing echo $this->render()? > > >>> On Sep 14, 11:36 am, Thomas Ploch<[email protected]> wrote: > >>>> As an addition, check outhttp://book.cakephp.org/view/980/render > > >>>> Am 14.09.2011 17:14, schrieb 8vius: > > >>>>> Can you be a little more explicit? I have my ajax action set up that > >>>>> will return a json encoded array. How can I get the html for the > >>>>> element from my controller? Maybe some example code? I'm a bit of a > >>>>> noob with this in general. Thank you. > > >>>>> On Sep 14, 11:05 am, Thomas Ploch<[email protected]> wrote: > >>>>>> The easiest way would be an AJAX action that renders the element with > >>>>>> the given POST data. The you can just use the rendered HTML and inject > >>>>>> it into the DOM. > > >>>>>> Kind regards > >>>>>> Thomas > > >>>>>> Am 14.09.2011 16:55, schrieb 8vius: > > >>>>>>> Hey all, got a little problem here. I wanna do something similar to > >>>>>>> what twitter does when you post a new tweet, that it automatically > >>>>>>> adds itself to the stream. I have made an element for this, the > >>>>>>> element receives my model data and sets it up properly but I'm not > >>>>>>> sure how to pass in the data from Jquery (I receive a JSON object). So > >>>>>>> what are my options here? How can I accomplish this? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
