<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: AJAX in CakePHP with jQuery</title>
	<atom:link href="http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/</link>
	<description>Making happy users!</description>
	<lastBuildDate>Tue, 22 Nov 2011 07:12:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Chris</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-1031</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Wed, 19 Jan 2011 18:45:36 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-1031</guid>
		<description>Hey ZedR,
I had the same issue and solved it:
add the following line before 
&lt;code&gt;$this-&gt;autoRender = false&lt;/code&gt;:

&lt;code&gt;Configure::write ( &#039;debug&#039;, 0 );&lt;/code&gt;

I&#039;m using CakePHP 1.3.6
Hope it helps (btw, great article!)</description>
		<content:encoded><![CDATA[<p>Hey ZedR,<br />
I had the same issue and solved it:<br />
add the following line before<br />
<code>$this-&gt;autoRender = false</code>:</p>
<p><code>Configure::write ( 'debug', 0 );</code></p>
<p>I&#8217;m using CakePHP 1.3.6<br />
Hope it helps (btw, great article!)
<p><span id="reportcomment_results_div_1031"><a href="javascript:void(0);" onclick="reportComment( 1031 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ZedR</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-577</link>
		<dc:creator>ZedR</dc:creator>
		<pubDate>Fri, 08 May 2009 14:24:50 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-577</guid>
		<description>Thanks for the reply Dhana.
I have checked my code. It does add record to the db. I even tried something else to return as return value, but still no success.</description>
		<content:encoded><![CDATA[<p>Thanks for the reply Dhana.<br />
I have checked my code. It does add record to the db. I even tried something else to return as return value, but still no success.
<p><span id="reportcomment_results_div_577"><a href="javascript:void(0);" onclick="reportComment( 577 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhana</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-576</link>
		<dc:creator>Dhana</dc:creator>
		<pubDate>Thu, 07 May 2009 19:54:37 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-576</guid>
		<description>ZedR,

Your JS code looks all right.  Did you check to make sure the user was created and added to the db?  I guess you could echo the value onto the page first to see if the user is indeed being retrieved after being saved.  Also try the Firebug tool to see if the error is happening during the submission process.</description>
		<content:encoded><![CDATA[<p>ZedR,</p>
<p>Your JS code looks all right.  Did you check to make sure the user was created and added to the db?  I guess you could echo the value onto the page first to see if the user is indeed being retrieved after being saved.  Also try the Firebug tool to see if the error is happening during the submission process.
<p><span id="reportcomment_results_div_576"><a href="javascript:void(0);" onclick="reportComment( 576 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ZedR</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-575</link>
		<dc:creator>ZedR</dc:creator>
		<pubDate>Thu, 07 May 2009 04:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-575</guid>
		<description>Dhana,

My jquery code: 

$(&#039;.add&#039;).click(function () {
var formData = $(this).parents(&#039;form&#039;).serialize();
                        

            $.ajax({
            type: &#039;POST&#039;,
            url: &#039;/blog/users/register&#039;,
            data: formData,
            dataType: &#039;json&#039;,
            success: function(rowData){
                var reg_html = &#039;Thank you. Please check email for the confirmation link. Click on it to activate account.&#039;;
                reg_html += &#039;Resend email? Click here:&#039;;
                reg_html += &#039;&#039;;
                $(&#039;#registeration&#039;).html(reg_html);
            },
            error: function(message){
                alert(message);                
            }

            });
       // }
    return false;
});

form view:

create(&#039;User&#039;,array(&#039;action&#039;=&gt;&#039;register&#039;,&#039;id&#039;=&gt;&#039;register&#039;, &#039;class&#039;=&gt;&#039;form&#039;)));?&gt;
    
        Register user
        input(&#039;firstname&#039;, array(&#039;label&#039;=&gt;&#039;First name&#039;, &#039;id&#039;=&gt;&#039;firstname&#039;)));?&gt;
        input(&#039;lastname&#039;, array(&#039;label&#039;=&gt;&#039;Last name&#039;, &#039;id&#039;=&gt;&#039;lastname&#039;)));?&gt;
        input(&#039;email&#039;, array(&#039;label&#039;=&gt;&#039;Email&#039;, &#039;id&#039;=&gt;&#039;email&#039;)));?&gt;
        input(&#039;password&#039;, array(&#039;label&#039;=&gt;&#039;Password&#039;, &#039;id&#039;=&gt;&#039;password&#039;,&#039;type&#039;=&gt;&#039;password&#039;)));?&gt;
        input(&#039;confirm_password&#039;, array(&#039;label&#039;=&gt;&#039;Confirm Password&#039;, &#039;id&#039;=&gt;&#039;confirm_password&#039;, &#039;type&#039;=&gt;&#039;password&#039;)));?&gt;
        input(&#039;sec_que&#039;, array(&#039;label&#039;=&gt;&#039;Security question&#039;, &#039;id&#039;=&gt;&#039;sec_que&#039;)));?&gt;
        input(&#039;sec_ans&#039;, array(&#039;label&#039;=&gt;&#039;Security answer&#039;, &#039;id&#039;=&gt;&#039;sec_ans&#039;)));?&gt;
        submit(&#039;Submit&#039;,array(&#039;class&#039;=&gt;&#039;add&#039;)));?&gt;
    
    end());?&gt;

register action in User controller:


if(!empty($this-&gt;data)) {
            //unset($this-&gt;data[&#039;User&#039;][&#039;confirm_password&#039;]);
            $this-&gt;data[&#039;User&#039;][&#039;password&#039;] = $this-&gt;Auth-&gt;password($this-&gt;data[&#039;User&#039;][&#039;password&#039;]);
            $this-&gt;data[&#039;User&#039;][&#039;confirm_password&#039;] = $this-&gt;Auth-&gt;password($this-&gt;data[&#039;User&#039;][&#039;confirm_password&#039;]);
            $this-&gt;User-&gt;create();
            $this-&gt;data = Sanitize::clean($this-&gt;data);
            if($this-&gt;User-&gt;save($this-&gt;data,false)) {

                $this-&gt;sendConfirmationEmail($this-&gt;data[&#039;User&#039;][&#039;email&#039;],$this-&gt;data[&#039;User&#039;][&#039;firstname&#039;], $this-&gt;data[&#039;User&#039;][&#039;password&#039;]);
                //$userdata = $this-&gt;data;
                $id = $this-&gt;User-&gt;getInsertID();
                $this-&gt;User-&gt;recursive = -1;
                if($this-&gt;RequestHandler-&gt;isAjax()) {
                    $this-&gt;autoRender = false;
                    $user=$this-&gt;User-&gt;findById($id);
                    return(json_encode($user));                    
                 }
                else {
                    $this-&gt;Session-&gt;setFlash(&#039;Your account has been created&#039;, &#039;default&#039;);
                }
}

The ajax operation always returns error. I tried data.User.email in the jquery code too instead of rowData.User.email. 
Thanks a lot.</description>
		<content:encoded><![CDATA[<p>Dhana,</p>
<p>My jquery code: </p>
<p>$(&#8216;.add&#8217;).click(function () {<br />
var formData = $(this).parents(&#8216;form&#8217;).serialize();</p>
<p>            $.ajax({<br />
            type: &#8216;POST&#8217;,<br />
            url: &#8216;/blog/users/register&#8217;,<br />
            data: formData,<br />
            dataType: &#8216;json&#8217;,<br />
            success: function(rowData){<br />
                var reg_html = &#8216;Thank you. Please check email for the confirmation link. Click on it to activate account.&#8217;;<br />
                reg_html += &#8216;Resend email? Click here:&#8217;;<br />
                reg_html += &#8221;;<br />
                $(&#8216;#registeration&#8217;).html(reg_html);<br />
            },<br />
            error: function(message){<br />
                alert(message);<br />
            }</p>
<p>            });<br />
       // }<br />
    return false;<br />
});</p>
<p>form view:</p>
<p>create(&#8216;User&#8217;,array(&#8216;action&#8217;=&gt;&#8217;register&#8217;,'id&#8217;=&gt;&#8217;register&#8217;, &#8216;class&#8217;=&gt;&#8217;form&#8217;)));?&gt;</p>
<p>        Register user<br />
        input(&#8216;firstname&#8217;, array(&#8216;label&#8217;=&gt;&#8217;First name&#8217;, &#8216;id&#8217;=&gt;&#8217;firstname&#8217;)));?&gt;<br />
        input(&#8216;lastname&#8217;, array(&#8216;label&#8217;=&gt;&#8217;Last name&#8217;, &#8216;id&#8217;=&gt;&#8217;lastname&#8217;)));?&gt;<br />
        input(&#8216;email&#8217;, array(&#8216;label&#8217;=&gt;&#8217;Email&#8217;, &#8216;id&#8217;=&gt;&#8217;email&#8217;)));?&gt;<br />
        input(&#8216;password&#8217;, array(&#8216;label&#8217;=&gt;&#8217;Password&#8217;, &#8216;id&#8217;=&gt;&#8217;password&#8217;,'type&#8217;=&gt;&#8217;password&#8217;)));?&gt;<br />
        input(&#8216;confirm_password&#8217;, array(&#8216;label&#8217;=&gt;&#8217;Confirm Password&#8217;, &#8216;id&#8217;=&gt;&#8217;confirm_password&#8217;, &#8216;type&#8217;=&gt;&#8217;password&#8217;)));?&gt;<br />
        input(&#8216;sec_que&#8217;, array(&#8216;label&#8217;=&gt;&#8217;Security question&#8217;, &#8216;id&#8217;=&gt;&#8217;sec_que&#8217;)));?&gt;<br />
        input(&#8216;sec_ans&#8217;, array(&#8216;label&#8217;=&gt;&#8217;Security answer&#8217;, &#8216;id&#8217;=&gt;&#8217;sec_ans&#8217;)));?&gt;<br />
        submit(&#8216;Submit&#8217;,array(&#8216;class&#8217;=&gt;&#8217;add&#8217;)));?&gt;</p>
<p>    end());?&gt;</p>
<p>register action in User controller:</p>
<p>if(!empty($this-&gt;data)) {<br />
            //unset($this-&gt;data['User']['confirm_password']);<br />
            $this-&gt;data['User']['password'] = $this-&gt;Auth-&gt;password($this-&gt;data['User']['password']);<br />
            $this-&gt;data['User']['confirm_password'] = $this-&gt;Auth-&gt;password($this-&gt;data['User']['confirm_password']);<br />
            $this-&gt;User-&gt;create();<br />
            $this-&gt;data = Sanitize::clean($this-&gt;data);<br />
            if($this-&gt;User-&gt;save($this-&gt;data,false)) {</p>
<p>                $this-&gt;sendConfirmationEmail($this-&gt;data['User']['email'],$this-&gt;data['User']['firstname'], $this-&gt;data['User']['password']);<br />
                //$userdata = $this-&gt;data;<br />
                $id = $this-&gt;User-&gt;getInsertID();<br />
                $this-&gt;User-&gt;recursive = -1;<br />
                if($this-&gt;RequestHandler-&gt;isAjax()) {<br />
                    $this-&gt;autoRender = false;<br />
                    $user=$this-&gt;User-&gt;findById($id);<br />
                    return(json_encode($user));<br />
                 }<br />
                else {<br />
                    $this-&gt;Session-&gt;setFlash(&#8216;Your account has been created&#8217;, &#8216;default&#8217;);<br />
                }<br />
}</p>
<p>The ajax operation always returns error. I tried data.User.email in the jquery code too instead of rowData.User.email.<br />
Thanks a lot.
<p><span id="reportcomment_results_div_575"><a href="javascript:void(0);" onclick="reportComment( 575 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhana</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-574</link>
		<dc:creator>Dhana</dc:creator>
		<pubDate>Wed, 06 May 2009 19:44:45 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-574</guid>
		<description>ZedR,
Do you have a test page that I could see?  rowData is the result returned by the server, which in this case is the json string of the newly added row.</description>
		<content:encoded><![CDATA[<p>ZedR,<br />
Do you have a test page that I could see?  rowData is the result returned by the server, which in this case is the json string of the newly added row.
<p><span id="reportcomment_results_div_574"><a href="javascript:void(0);" onclick="reportComment( 574 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ZedR</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-573</link>
		<dc:creator>ZedR</dc:creator>
		<pubDate>Wed, 06 May 2009 15:27:57 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-573</guid>
		<description>Nice!!

I am trying to do the same thing but I m getting [object XMLHttpRequest] in the error message. What must be the problem? I checked the formData. It starts with _method=POST&amp;data.... What is rowData?</description>
		<content:encoded><![CDATA[<p>Nice!!</p>
<p>I am trying to do the same thing but I m getting [object XMLHttpRequest] in the error message. What must be the problem? I checked the formData. It starts with _method=POST&amp;data&#8230;. What is rowData?
<p><span id="reportcomment_results_div_573"><a href="javascript:void(0);" onclick="reportComment( 573 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimmy</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-525</link>
		<dc:creator>Jimmy</dc:creator>
		<pubDate>Sat, 18 Apr 2009 23:05:49 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-525</guid>
		<description>Most helpful post I&#039;ve found on this subject. Thanks very much!</description>
		<content:encoded><![CDATA[<p>Most helpful post I&#8217;ve found on this subject. Thanks very much!
<p><span id="reportcomment_results_div_525"><a href="javascript:void(0);" onclick="reportComment( 525 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhana</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-500</link>
		<dc:creator>Dhana</dc:creator>
		<pubDate>Fri, 10 Apr 2009 04:30:15 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-500</guid>
		<description>Glad you found it helpful :)</description>
		<content:encoded><![CDATA[<p>Glad you found it helpful <img src='http://idhana.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
<p><span id="reportcomment_results_div_500"><a href="javascript:void(0);" onclick="reportComment( 500 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: paul</title>
		<link>http://idhana.com/2009/03/29/ajax-in-cakephp-with-jquery/comment-page-1/#comment-497</link>
		<dc:creator>paul</dc:creator>
		<pubDate>Thu, 09 Apr 2009 13:30:16 +0000</pubDate>
		<guid isPermaLink="false">http://idhana.com/?p=340#comment-497</guid>
		<description>Thanks man! Finally the result of a long search, now i&#039;m lucky :)</description>
		<content:encoded><![CDATA[<p>Thanks man! Finally the result of a long search, now i&#8217;m lucky <img src='http://idhana.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
<p><span id="reportcomment_results_div_497"><a href="javascript:void(0);" onclick="reportComment( 497 );" title="Report this comment" rel="nofollow">Report this comment</a></span></p>
]]></content:encoded>
	</item>
</channel>
</rss>

