<?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: 5 tips for using AJAX in WordPress</title>
	<atom:link href="http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/</link>
	<description>Freelance Web Developer</description>
	<lastBuildDate>Thu, 07 Apr 2011 10:09:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Robert</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-511</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Thu, 07 Apr 2011 10:09:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-511</guid>
		<description>Very goooood tutorial!!! :) It&#039;s very helpfull</description>
		<content:encoded><![CDATA[<p>Very goooood tutorial!!! <img src='http://www.garyc40.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It&#8217;s very helpfull</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Cao</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-491</link>
		<dc:creator>Gary Cao</dc:creator>
		<pubDate>Sat, 26 Mar 2011 10:08:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-491</guid>
		<description>You should use add_action() instead of do_action():

[php]
add_action( &#039;wp_ajax_submit-logout&#039;, &#039;my_plugin_submit_logout&#039; );
add_action( &#039;wp_ajax_star-rating&#039;, &#039;my_plugin_star_rating&#039; );
[/php]

&#039;my_plugin_submit_logout&#039; and &#039;my_plugin_star_rating&#039; are 2 functions that handle your request. &#039;submit-logout&#039; and &#039;star-rating&#039; are the action parameters of the request.

If you&#039;re still stuck, please send me an email with your code (garyc40 [at] garyc40.com), I&#039;ll try to help out as soon as I have some time :)</description>
		<content:encoded><![CDATA[<p>You should use add_action() instead of do_action():</p>
<pre class="brush: php; title: ;">
add_action( 'wp_ajax_submit-logout', 'my_plugin_submit_logout' );
add_action( 'wp_ajax_star-rating', 'my_plugin_star_rating' );
</pre>
<p>&#8216;my_plugin_submit_logout&#8217; and &#8216;my_plugin_star_rating&#8217; are 2 functions that handle your request. &#8216;submit-logout&#8217; and &#8216;star-rating&#8217; are the action parameters of the request.</p>
<p>If you&#8217;re still stuck, please send me an email with your code (garyc40 [at] garyc40.com), I&#8217;ll try to help out as soon as I have some time <img src='http://www.garyc40.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Cauthorn</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-489</link>
		<dc:creator>Dan Cauthorn</dc:creator>
		<pubDate>Wed, 23 Mar 2011 21:50:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-489</guid>
		<description>Hey Gary,
Thanks a ton for the great explication on good AJAX practices in Wordpress. I&#039;m actually having a problem with one ajax request unintentionally  triggering another.   I have a logout  ajax function that is set up in admin-ajax.php   as:

do_action( &#039;wp_ajax_submit_logout&#039;, $_REQUEST[&#039;action&#039;] );

 and a star rating function set up just below (using the handle from your example)

do_action( &#039;wp_ajax_myajax-submit&#039;, $_REQUEST[&#039;action&#039;] ); 

Then I set up their  respective add_action(&#039; &#039;)  in the functions folder.  The result: when I fire the star rating function, the AJAX request triggers the logout function as well !

I&#039;m assuming it&#039;s okay to have more than one AJAX hook set up in admin-ajax, right?

If you could tell me what I&#039;m doing wrong,  I&#039;d be forever thankful ! 

Thanks !
Dan</description>
		<content:encoded><![CDATA[<p>Hey Gary,<br />
Thanks a ton for the great explication on good AJAX practices in WordPress. I&#8217;m actually having a problem with one ajax request unintentionally  triggering another.   I have a logout  ajax function that is set up in admin-ajax.php   as:</p>
<p>do_action( &#8216;wp_ajax_submit_logout&#8217;, $_REQUEST['action'] );</p>
<p> and a star rating function set up just below (using the handle from your example)</p>
<p>do_action( &#8216;wp_ajax_myajax-submit&#8217;, $_REQUEST['action'] ); </p>
<p>Then I set up their  respective add_action(&#8216; &#8216;)  in the functions folder.  The result: when I fire the star rating function, the AJAX request triggers the logout function as well !</p>
<p>I&#8217;m assuming it&#8217;s okay to have more than one AJAX hook set up in admin-ajax, right?</p>
<p>If you could tell me what I&#8217;m doing wrong,  I&#8217;d be forever thankful ! </p>
<p>Thanks !<br />
Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Cao</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-488</link>
		<dc:creator>Gary Cao</dc:creator>
		<pubDate>Sun, 20 Mar 2011 17:44:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-488</guid>
		<description>Yes, that&#039;s because at the beginning of &lt;code&gt;admin-ajax.php&lt;/code&gt;, the constant &lt;code&gt;WP_ADMIN&lt;/code&gt; is defined as &lt;code&gt;true&lt;/code&gt;. This might be counter-intuitive, as &lt;code&gt;admin-ajax.php&lt;/code&gt; can be used on the front-end as well. You might want to file a ticket on WordPress Core Trac to mention this inconsistency to core developers.

In the mean time, instead of &lt;code&gt;is_admin()&lt;/code&gt;, you can use &lt;code&gt;is_user_logged_in()&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>Yes, that&#8217;s because at the beginning of <code>admin-ajax.php</code>, the constant <code>WP_ADMIN</code> is defined as <code>true</code>. This might be counter-intuitive, as <code>admin-ajax.php</code> can be used on the front-end as well. You might want to file a ticket on WordPress Core Trac to mention this inconsistency to core developers.</p>
<p>In the mean time, instead of <code>is_admin()</code>, you can use <code>is_user_logged_in()</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: saintist</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-487</link>
		<dc:creator>saintist</dc:creator>
		<pubDate>Fri, 18 Mar 2011 23:39:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-487</guid>
		<description>ajax url  http://my...site.com/wp-admin/admin-ajax.php</description>
		<content:encoded><![CDATA[<p>ajax url  <a href="http://my...site.com/wp-admin/admin-ajax.php" rel="nofollow">http://my&#8230;site.com/wp-admin/admin-ajax.php</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: saintist</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-486</link>
		<dc:creator>saintist</dc:creator>
		<pubDate>Fri, 18 Mar 2011 23:38:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-486</guid>
		<description>i  usage 

add_action(&#039;wp_ajax_myplugin&#039;, array(&amp;$this,&#039;ajax&#039;));
 /
add_action(&#039;wp_ajax_nopriv_myplugin&#039;, array(&amp;$this,&#039;ajax&#039;));


I have a problem, I develop a plugin widget in the plugin adds a text output at each end of the record office, and there is a button in a form for sending Ajax requests sent from the home page constantly Ajax request is identified through is_admin () as true

any ideas?</description>
		<content:encoded><![CDATA[<p>i  usage </p>
<p>add_action(&#8216;wp_ajax_myplugin&#8217;, array(&amp;$this,&#8217;ajax&#8217;));<br />
 /<br />
add_action(&#8216;wp_ajax_nopriv_myplugin&#8217;, array(&amp;$this,&#8217;ajax&#8217;));</p>
<p>I have a problem, I develop a plugin widget in the plugin adds a text output at each end of the record office, and there is a button in a form for sending Ajax requests sent from the home page constantly Ajax request is identified through is_admin () as true</p>
<p>any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Riccardo</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-258</link>
		<dc:creator>Riccardo</dc:creator>
		<pubDate>Tue, 21 Dec 2010 12:50:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-258</guid>
		<description>Nice article man! Thank you, Merry Xmas!</description>
		<content:encoded><![CDATA[<p>Nice article man! Thank you, Merry Xmas!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimmyy</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-237</link>
		<dc:creator>Jimmyy</dc:creator>
		<pubDate>Sat, 18 Dec 2010 20:11:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-237</guid>
		<description>Hi,
Great article, but a bit difficult to understand for developpers that are not familliar with all the inner workings of wordpress.

  It could be of great use, if you could explain in exactly which file every piece of code needs to be written.
I got the big picture that the admin-ajax.php is used, I have it open,but for example where do I need to add the first code snippet:
// embed the javascript file that makes the AJAX request

2 wp_enqueue_script( &#039;my-ajax-request&#039;, plugin_dir_url( __FILE__ ) . &#039;js/ajax.js&#039;, array( &#039;jquery&#039; ) );

3

4 // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php)

5 wp_localize_script( &#039;my-ajax-request&#039;, &#039;MyAjax&#039;, array( &#039;ajaxurl&#039; =&gt; admin_url( &#039;admin-ajax.php&#039; ) ) );

Do I need to add it to the admin-ajax.php? I guess not, but then where in which file?

Great article though,
Thanks
Jimmyy</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Great article, but a bit difficult to understand for developpers that are not familliar with all the inner workings of wordpress.</p>
<p>  It could be of great use, if you could explain in exactly which file every piece of code needs to be written.<br />
I got the big picture that the admin-ajax.php is used, I have it open,but for example where do I need to add the first code snippet:<br />
// embed the javascript file that makes the AJAX request</p>
<p>2 wp_enqueue_script( &#8216;my-ajax-request&#8217;, plugin_dir_url( __FILE__ ) . &#8216;js/ajax.js&#8217;, array( &#8216;jquery&#8217; ) );</p>
<p>3</p>
<p>4 // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php)</p>
<p>5 wp_localize_script( &#8216;my-ajax-request&#8217;, &#8216;MyAjax&#8217;, array( &#8216;ajaxurl&#8217; =&gt; admin_url( &#8216;admin-ajax.php&#8217; ) ) );</p>
<p>Do I need to add it to the admin-ajax.php? I guess not, but then where in which file?</p>
<p>Great article though,<br />
Thanks<br />
Jimmyy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: baker</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-234</link>
		<dc:creator>baker</dc:creator>
		<pubDate>Sat, 18 Dec 2010 12:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-234</guid>
		<description>wow, this is really great stuff! thanks for the info. just need to add the nonces part. :)</description>
		<content:encoded><![CDATA[<p>wow, this is really great stuff! thanks for the info. just need to add the nonces part. <img src='http://www.garyc40.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#comment-159</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Mon, 22 Nov 2010 05:17:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.wphardcore.com/?p=39#comment-159</guid>
		<description>This article is great. Highly recommended for plugin developers looking to beef up their support for AJAX. The addition of the nonce security bit was extremely well explained and very helpful. Keep up the good work!</description>
		<content:encoded><![CDATA[<p>This article is great. Highly recommended for plugin developers looking to beef up their support for AJAX. The addition of the nonce security bit was extremely well explained and very helpful. Keep up the good work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

