<?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: How to update multiple divs with Ajax</title>
	<atom:link href="http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:12: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: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-104031</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 22 Aug 2008 15:59:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-104031</guid>
		<description>@Kapil: Thanks for your comment! 

You might consider to open an enhancement ticket to include this functionality into the core AjaxHelper.</description>
		<content:encoded><![CDATA[<p>@Kapil: Thanks for your comment! </p>
<p>You might consider to open an enhancement ticket to include this functionality into the core AjaxHelper.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kapil</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-103904</link>
		<dc:creator>Kapil</dc:creator>
		<pubDate>Thu, 21 Aug 2008 14:15:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-103904</guid>
		<description>I have triggered multiple actions and updated multiple divs on single Ajax request by extending ajaxHelper
&lt;code&gt;
&lt;?php
class MyAjaxHelper extends AjaxHelper {

/**
 * Returns link to remote action
 *
 * Returns a link to a remote action defined by &lt;i&gt;options[url]&lt;/i&gt;
 * (using the url() format) that&#039;s called in the background using
 * XMLHttpRequest. The result of that request can then be inserted into a
 * DOM object whose id can be specified with &lt;i&gt;options[update]&lt;/i&gt;.
 *
 * Examples:
 * &lt;code&gt;
 *  link(&quot;Delete this post&quot;,
 * array(&quot;update&quot; =&gt; &quot;posts&quot;, &quot;url&quot; =&gt; &quot;delete/{$postid-&gt;id}&quot;));
 *  link(imageTag(&quot;refresh&quot;),
 *		array(&quot;update&quot; =&gt; &quot;emails&quot;, &quot;url&quot; =&gt; &quot;list_emails&quot; ));
 * &lt;/code&gt;
 *
 * By default, these remote requests are processed asynchronous during
 * which various callbacks can be triggered (for progress indicators and
 * the likes).
 *
 * Example:
 * &lt;code&gt;
 *	link (word,
 *		array(&quot;url&quot; =&gt; &quot;undo&quot;, &quot;n&quot; =&gt; word_counter),
 *		array(&quot;complete&quot; =&gt; &quot;undoRequestCompleted(request)&quot;));
 * &lt;/code&gt;
 *
 * The callbacks that may be specified are:
 *
 * - &lt;i&gt;loading&lt;/i&gt;::		Called when the remote document is being
 *							loaded with data by the browser.
 * - &lt;i&gt;loaded&lt;/i&gt;::		Called when the browser has finished loading
 *							the remote document.
 * - &lt;i&gt;interactive&lt;/i&gt;::	Called when the user can interact with the
 *							remote document, even though it has not
 *							finished loading.
 * - &lt;i&gt;complete&lt;/i&gt;:: Called when the XMLHttpRequest is complete.
 *
 * If you for some reason or another need synchronous processing (that&#039;ll
 * block the browser while the request is happening), you can specify
 * &lt;i&gt;options[type] = synchronous&lt;/i&gt;.
 *
 * You can customize further browser side call logic by passing
 * in Javascript code snippets via some optional parameters. In
 * their order of use these are:
 *
 * - &lt;i&gt;confirm&lt;/i&gt;:: Adds confirmation dialog.
 * -&lt;i&gt;condition&lt;/i&gt;::	Perform remote request conditionally
 *                      by this expression. Use this to
 *                      describe browser-side conditions when
 *                      request should not be initiated.
 * - &lt;i&gt;before&lt;/i&gt;::		Called before request is initiated.
 * - &lt;i&gt;after&lt;/i&gt;::		Called immediately after request was
 *						initiated and before &lt;i&gt;loading&lt;/i&gt;.
 *
 * @param string $title Title of link
 * @param string $href Href string &quot;/products/view/12&quot;
 * @param array $options		Options for JavaScript function
 * @param string $confirm		Confirmation message. Calls up a JavaScript confirm() message.
 * @param boolean $escapeTitle  Escaping the title string to HTML entities
 *
 * @return string				HTML code for link to remote action
 */
	function link($title, $href = null, $options = array(), $confirm = null, $escapeTitle = true) {
		if (!isset($href)) {
			$href = $title;
		}
		if (!isset($options[&#039;url&#039;])) {
			$options[&#039;url&#039;] = $href;
		}		

		if (isset($confirm)) {
			$options[&#039;confirm&#039;] = $confirm;
			unset($confirm);
		}
		$htmlOptions = $this-&gt;__getHtmlOptions($options, array(&#039;url&#039;));

		if (empty($options[&#039;fallback&#039;]) &#124;&#124; !isset($options[&#039;fallback&#039;])) {
			$options[&#039;fallback&#039;] = $href;
		}
		$htmlOptions = array_merge(array(&#039;id&#039; =&gt; &#039;link&#039; . intval(rand()), &#039;onclick&#039; =&gt; &#039;&#039;), $htmlOptions);

		$htmlOptions[&#039;onclick&#039;] .= &#039; event.returnValue = false; return false;&#039;;
		$return = $this-&gt;Html-&gt;link($title, $href, $htmlOptions, null, $escapeTitle);
//		pr($options);
		if(is_array($options[&#039;url&#039;]) &amp;&amp; is_array($options[&#039;update&#039;]))
		{
			$script=&quot;&quot;;
			$opts=array();
			foreach($options[&#039;url&#039;] as $key=&gt;$val){
				$opts[$key][&#039;url&#039;]=$val;
			}
			foreach($options[&#039;update&#039;] as $key=&gt;$val){
				$opts[$key][&#039;update&#039;]=$val;
				$opts[$key][&#039;fallback&#039;]=$options[&#039;fallback&#039;];
				$opts[$key][&#039;indicator&#039;]=$options[&#039;indicator&#039;];
				$script .= $this-&gt;Javascript-&gt;event(&quot;&#039;{$htmlOptions[&#039;id&#039;]}&#039;&quot;, &quot;click&quot;, $this-&gt;remoteFunction($opts[$key]));
			}
		}		

		if (is_string($script)) {
			$return .= $script;
		}
		return $return;
	}
	
	function submit($title = &#039;Submit&#039;, $options = array()) {
		$htmlOptions = $this-&gt;__getHtmlOptions($options);
		$htmlOptions[&#039;value&#039;] = $title;

		if (!isset($options[&#039;with&#039;])) {
			$options[&#039;with&#039;] = &#039;Form.serialize(Event.element(event).form)&#039;;
		}
		if (!isset($htmlOptions[&#039;id&#039;])) {
			$htmlOptions[&#039;id&#039;] = &#039;submit&#039; . intval(rand());
		}
		
		if(is_array($options[&#039;url&#039;]) &amp;&amp; is_array($options[&#039;update&#039;]))
		{
			$script=&quot;&quot;;
			$opts=array();
			foreach($options[&#039;url&#039;] as $key=&gt;$val){
				$opts[$key][&#039;url&#039;]=$val;
			}
			foreach($options[&#039;update&#039;] as $key=&gt;$val){
				$opts[$key][&#039;update&#039;]=$val;
				$opts[$key][&#039;class&#039;]=$options[&#039;class&#039;];
				$opts[$key][&#039;with&#039;]=$options[&#039;with&#039;];
				$script .= $this-&gt;Javascript-&gt;event(&#039;&quot;&#039; . $htmlOptions[&#039;id&#039;] . &#039;&quot;&#039;, &#039;click&#039;, $this-&gt;remoteFunction($opts[$key]));
			}			
		}
		$htmlOptions[&#039;onclick&#039;] = &quot;event.returnValue = false; return false;&quot;;
		return $this-&gt;Form-&gt;submit($title, $htmlOptions).$script;
	}
}
?&gt;

// How to use

submit(&#039;submit&#039;,array(&#039;url&#039; =&gt; array(&#039;url 1 here&#039;,&#039;url 2 here&#039;), &#039;update&#039; =&gt; array(&#039;div 1 here&#039;,&#039;div 2 here&#039;)));	?&gt;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I have triggered multiple actions and updated multiple divs on single Ajax request by extending ajaxHelper<br />
<pre><code>&lt;?php
class MyAjaxHelper extends AjaxHelper {

/**
 * Returns link to remote action
 *
 * Returns a link to a remote action defined by &lt;i&gt;options[url]&lt;/i&gt;
 * (using the url() format) that's called in the background using
 * XMLHttpRequest. The result of that request can then be inserted into a
 * DOM object whose id can be specified with &lt;i&gt;options[update]&lt;/i&gt;.
 *
 * Examples:
 * &amp;lt;code&amp;gt;
 *  link("Delete this post",
 * array("update" =&gt; "posts", "url" =&gt; "delete/{$postid-&gt;id}"));
 *  link(imageTag("refresh"),
 *		array("update" =&gt; "emails", "url" =&gt; "list_emails" ));
 * &amp;lt;/code&amp;gt;
 *
 * By default, these remote requests are processed asynchronous during
 * which various callbacks can be triggered (for progress indicators and
 * the likes).
 *
 * Example:
 * &amp;lt;code&amp;gt;
 *	link (word,
 *		array("url" =&gt; "undo", "n" =&gt; word_counter),
 *		array("complete" =&gt; "undoRequestCompleted(request)"));
 * &amp;lt;/code&amp;gt;
 *
 * The callbacks that may be specified are:
 *
 * - &lt;i&gt;loading&lt;/i&gt;::		Called when the remote document is being
 *							loaded with data by the browser.
 * - &lt;i&gt;loaded&lt;/i&gt;::		Called when the browser has finished loading
 *							the remote document.
 * - &lt;i&gt;interactive&lt;/i&gt;::	Called when the user can interact with the
 *							remote document, even though it has not
 *							finished loading.
 * - &lt;i&gt;complete&lt;/i&gt;:: Called when the XMLHttpRequest is complete.
 *
 * If you for some reason or another need synchronous processing (that'll
 * block the browser while the request is happening), you can specify
 * &lt;i&gt;options[type] = synchronous&lt;/i&gt;.
 *
 * You can customize further browser side call logic by passing
 * in Javascript code snippets via some optional parameters. In
 * their order of use these are:
 *
 * - &lt;i&gt;confirm&lt;/i&gt;:: Adds confirmation dialog.
 * -&lt;i&gt;condition&lt;/i&gt;::	Perform remote request conditionally
 *                      by this expression. Use this to
 *                      describe browser-side conditions when
 *                      request should not be initiated.
 * - &lt;i&gt;before&lt;/i&gt;::		Called before request is initiated.
 * - &lt;i&gt;after&lt;/i&gt;::		Called immediately after request was
 *						initiated and before &lt;i&gt;loading&lt;/i&gt;.
 *
 * @param string $title Title of link
 * @param string $href Href string "/products/view/12"
 * @param array $options		Options for JavaScript function
 * @param string $confirm		Confirmation message. Calls up a JavaScript confirm() message.
 * @param boolean $escapeTitle  Escaping the title string to HTML entities
 *
 * @return string				HTML code for link to remote action
 */
	function link($title, $href = null, $options = array(), $confirm = null, $escapeTitle = true) {
		if (!isset($href)) {
			$href = $title;
		}
		if (!isset($options['url'])) {
			$options['url'] = $href;
		}		

		if (isset($confirm)) {
			$options['confirm'] = $confirm;
			unset($confirm);
		}
		$htmlOptions = $this-&amp;gt;__getHtmlOptions($options, array('url'));

		if (empty($options['fallback']) || !isset($options['fallback'])) {
			$options['fallback'] = $href;
		}
		$htmlOptions = array_merge(array('id' =&amp;gt; 'link' . intval(rand()), 'onclick' =&amp;gt; ''), $htmlOptions);

		$htmlOptions['onclick'] .= ' event.returnValue = false; return false;';
		$return = $this-&amp;gt;Html-&amp;gt;link($title, $href, $htmlOptions, null, $escapeTitle);
//		pr($options);
		if(is_array($options['url']) &amp;amp;&amp;amp; is_array($options['update']))
		{
			$script="";
			$opts=array();
			foreach($options['url'] as $key=&amp;gt;$val){
				$opts[$key]['url']=$val;
			}
			foreach($options['update'] as $key=&amp;gt;$val){
				$opts[$key]['update']=$val;
				$opts[$key]['fallback']=$options['fallback'];
				$opts[$key]['indicator']=$options['indicator'];
				$script .= $this-&amp;gt;Javascript-&amp;gt;event("'{$htmlOptions['id']}'", "click", $this-&amp;gt;remoteFunction($opts[$key]));
			}
		}		

		if (is_string($script)) {
			$return .= $script;
		}
		return $return;
	}
	
	function submit($title = 'Submit', $options = array()) {
		$htmlOptions = $this-&amp;gt;__getHtmlOptions($options);
		$htmlOptions['value'] = $title;

		if (!isset($options['with'])) {
			$options['with'] = 'Form.serialize(Event.element(event).form)';
		}
		if (!isset($htmlOptions['id'])) {
			$htmlOptions['id'] = 'submit' . intval(rand());
		}
		
		if(is_array($options['url']) &amp;amp;&amp;amp; is_array($options['update']))
		{
			$script="";
			$opts=array();
			foreach($options['url'] as $key=&amp;gt;$val){
				$opts[$key]['url']=$val;
			}
			foreach($options['update'] as $key=&amp;gt;$val){
				$opts[$key]['update']=$val;
				$opts[$key]['class']=$options['class'];
				$opts[$key]['with']=$options['with'];
				$script .= $this-&amp;gt;Javascript-&amp;gt;event('"' . $htmlOptions['id'] . '"', 'click', $this-&amp;gt;remoteFunction($opts[$key]));
			}			
		}
		$htmlOptions['onclick'] = "event.returnValue = false; return false;";
		return $this-&amp;gt;Form-&amp;gt;submit($title, $htmlOptions).$script;
	}
}
?&amp;gt;

// How to use

submit('submit',array('url' =&amp;gt; array('url 1 here','url 2 here'), 'update' =&amp;gt; array('div 1 here','div 2 here')));	?&amp;gt;</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-83485</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 18 Apr 2008 15:08:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-83485</guid>
		<description>@gustavo: Cool to hear you got it done in the meantime :)</description>
		<content:encoded><![CDATA[<p>@gustavo: Cool to hear you got it done in the meantime :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gustavo bellino</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-83470</link>
		<dc:creator>gustavo bellino</dc:creator>
		<pubDate>Fri, 18 Apr 2008 14:11:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-83470</guid>
		<description>i could do it!!! :D
i followed this link
http://www.reversefolds.com/articles/show/ajax

regards</description>
		<content:encoded><![CDATA[<p>i could do it!!! :D<br />
i followed this link<br />
<a href="http://www.reversefolds.com/articles/show/ajax" rel="nofollow">http://www.reversefolds.com/articles/show/ajax</a></p>
<p>regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gustavo bellino</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-83461</link>
		<dc:creator>gustavo bellino</dc:creator>
		<pubDate>Fri, 18 Apr 2008 13:44:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-83461</guid>
		<description>i have two views first.thtml and secundo.thtml 
when i call the function in the controller i put the 
&lt;code&gt;
$this-&gt;render(&#039;first&#039;, &#039;ajax&#039;);
//for this example
&lt;/code&gt;
i also need to call the 
$this-&gt;render(&#039;second&#039;, &#039;ajax&#039;);

doing 
$this-&gt;render(&#039;first&#039;, &#039;ajax&#039;);
$this-&gt;render(&#039;second&#039;, &#039;ajax&#039;);
doesnt work

some help?
regards</description>
		<content:encoded><![CDATA[<p>i have two views first.thtml and secundo.thtml<br />
when i call the function in the controller i put the<br />
<pre><code>$this-&amp;gt;render('first', 'ajax');
//for this example</code></pre><br />
i also need to call the<br />
$this-&gt;render(&#8216;second&#8217;, &#8216;ajax&#8217;);</p>
<p>doing<br />
$this-&gt;render(&#8216;first&#8217;, &#8216;ajax&#8217;);<br />
$this-&gt;render(&#8216;second&#8217;, &#8216;ajax&#8217;);<br />
doesnt work</p>
<p>some help?<br />
regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-40023</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 04 Dec 2007 16:55:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-40023</guid>
		<description>@Tim: See Zonium&#039;s answer.

@Zonium: Thanks for providing the answer!</description>
		<content:encoded><![CDATA[<p>@Tim: See Zonium&#8217;s answer.</p>
<p>@Zonium: Thanks for providing the answer!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zonium</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-39928</link>
		<dc:creator>Zonium</dc:creator>
		<pubDate>Tue, 04 Dec 2007 07:50:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-39928</guid>
		<description>@Tim Daldini:
Turn on firebug and see some js snippet gets generated by the ajax div functions - so I guess that&#039;s the answer.

var __ajaxUpdater__ = {first:&quot;first%20div%20updated%3A%201196754195&quot;,
second:&quot;second%20div%20updated%0D%0A&quot;};
for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == &quot;string&quot; &amp;&amp; $(n)) Element.update($(n),
 unescape(decodeURIComponent(__ajaxUpdater__[n]))); }</description>
		<content:encoded><![CDATA[<p>@Tim Daldini:<br />
Turn on firebug and see some js snippet gets generated by the ajax div functions &#8211; so I guess that&#8217;s the answer.</p>
<p>var __ajaxUpdater__ = {first:&#8221;first%20div%20updated%3A%201196754195&#8243;,<br />
second:&#8221;second%20div%20updated%0D%0A&#8221;};<br />
for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == &#8220;string&#8221; &amp;&amp; $(n)) Element.update($(n),<br />
 unescape(decodeURIComponent(__ajaxUpdater__[n]))); }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Daldini</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-39866</link>
		<dc:creator>Tim Daldini</dc:creator>
		<pubDate>Tue, 04 Dec 2007 02:39:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-39866</guid>
		<description>What&#039;s the point in using ajax div functions in favour of html div functions?

I didnt really manage to understand the ajax helper code, but I think the ajax divs are conditionally rendered based on wheter or not an ajax request needs the div. Correct me if i&#039;m wrong...</description>
		<content:encoded><![CDATA[<p>What&#8217;s the point in using ajax div functions in favour of html div functions?</p>
<p>I didnt really manage to understand the ajax helper code, but I think the ajax divs are conditionally rendered based on wheter or not an ajax request needs the div. Correct me if i&#8217;m wrong&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-26642</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Thu, 01 Nov 2007 15:51:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-26642</guid>
		<description>@sidr: I am glad you could solve the problem in the meantime :)</description>
		<content:encoded><![CDATA[<p>@sidr: I am glad you could solve the problem in the meantime :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sidr</title>
		<link>http://cakebaker.42dh.com/2006/06/29/how-to-update-multiple-divs-with-ajax/comment-page-1/#comment-26245</link>
		<dc:creator>sidr</dc:creator>
		<pubDate>Wed, 31 Oct 2007 09:05:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=218#comment-26245</guid>
		<description>The problem was solved when I use $options[’loaded’] instead of $options[’after’]</description>
		<content:encoded><![CDATA[<p>The problem was solved when I use $options[’loaded’] instead of $options[’after’]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

