Cakephp Ajax Tutorial - Using Cakephp's Js Helper and jQuery
Uploader Comments (andrewperk)
Top Comments
-
I had the same issue. I found that the script was not wrapped jquery document ready function, so I had to add 'onDomReady'=>TRUE to the writeBuffer method call in the default.ctp. Not sure if this the right thing to do, but it worked.
echo $this->Js->writeBuffer(array('
cache'=>TRUE, 'onDomReady'=>TRUE)); In the comments of the writeBuffer function it says 'If the request is an XHR(ajax) request onDomReady will be set to false. As the dom is already 'ready'. Not sure what this means exactly.
All Comments (33)
-
@andrewperk Hi. You don't even need to use ids for the form elements. Hence reduced headache.
Example:
You can simply use $("input[name='name']"), $("input[name='email']") etc to access them :)
-
Thanks for the awesome tut!
-
@zoborowi This worked for me. Thanks!
-
can u do one where u can send an email?
-
Not sure if this is the same problem that you are having but, for me, I noticed that the js buffer script was not being created on my server. Turns out the permissions for the folder /webroot/js on my server were not set to be written to and buffer script file was never being created. I changed the permissions for that folder to 777 and now the buffer script is being created and the ajax is working. Not sure if that's the best fix but worked for me.
-
Thank You for your very clear presentation! Finally I could solve my problems to start learning ajax :) I want to thank You for your pronunciation and language too - english isn't my deal, but I like to listen and watch your videos.
-
Thank you for making this tutorial. Just what I needed for my current project. I have a question, is there a way of uploading files via AJAX? What I would like to do is upload an image via AJAX and then display its thumbnail on the same page as the form. I already have the image resizing part setup on the server.
-
Holy fck dude! I love your voice! Also thank you for free and so valuable knowledge!
-
Man, this is great, really helped me a lot with my current project. Both parts are great, but the raw jquery without JsHelper at the end is killer!
-
put $this->Js->writeBuffer(array('
cache' => TRUE)); in the end of form ctp file. And remove it from layout.ctp
In validation.js why u use $("#name").attr("id") or $("#name").val() ? You can write just $(this).attr("id") or $(this).val().
And then you dont need dublicate your code :)
unoLT 6 months ago 3
@unoLT Good tip, thank you.
andrewperk 6 months ago