Monday, April 29, 2013

Re: Any cake 2.x Ajax examples?

Hi

Most of the actual ajax is client side.  So lets assume you are using jQuery, and are familiar with how that works.

With CakePHP, the convention is to use file extension based routing to recognise XML or JSON requests.  For this, define Router::parseExtensions() in your router.php, as seen at http://book.cakephp.org/2.0/en/development/routing.html#file-extensions and http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#ajax-pagination.

I'll also want to enable the RequestHandler component, to recognise an AJAX request, as seen at http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#ajax-pagination.

If you're doing XML or JSON results for your AJAX calls, be sure to append .xml or .json to your requests.  You can also use the _serialize view property to help set up an XML or JSON response, without having to define an actual view. http://book.cakephp.org/2.0/en/views/json-and-xml-views.html

For HTML responses, just be sure to define an ajax.ctp layout that just outputs the contents.

If you're using AJAX with jQuery Mobile, then ignore all of that and just do regular HTML pages. JQM will extract the data it needs from the replies, and populate the pages accordingly.

On Monday, 29 April 2013 21:01:26 UTC+10, Yen Hua Chuah wrote:
Hi
Is there any documents on how to use Ajax in Cake 2.x?
I have been trying to read the cake user manual but it only shows methods and i cant really figure out how to use it.

please help

chris

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: