<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ajax | Subesh Pokhrel&#039;s Blog - Magento Development Tips,PHP,Google Maps</title>
	<atom:link href="http://subesh.com.np/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://subesh.com.np</link>
	<description>PHP &#38; Magento Tips &#38; Tutorials</description>
	<lastBuildDate>Thu, 12 Aug 2010 12:22:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ajax | Subesh Pokhrel&#039;s Blog - Magento Development Tips,PHP,Google Maps</title>
		<link>http://subesh.com.np/2009/11/working-with-ajax-in-magento/</link>
		<comments>http://subesh.com.np/2009/11/working-with-ajax-in-magento/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 13:50:14 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[Controllers]]></category>
		<category><![CDATA[Layout]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=82</guid>
		<description><![CDATA[Ajax in Magento can be pretty troublesome.Because you will need to take controllers and layout into account.And I almost used up a whole day trying to make ajax work. Here are some of the steps I&#8217;d like to share so that you will not waste lots of your time, before making this work  .
Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Ajax in Magento can be pretty troublesome.Because you will need to take controllers and layout into account.And I almost used up a whole day trying to make ajax work. Here are some of the steps I&#8217;d like to share so that you will not waste lots of your time, before making this work <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .<br />
Let&#8217;s first know in Magento terms what we need.</p>
<p><span id="more-82"></span></p>
<p><strong>Controller:</strong> The url on which Ajax will work on, or the request URL. You will have to set up the controller with its frontend router set in config.xml and its corresponding controller class.<br />
<strong>Layout:</strong> Layout to handle the requested URL and return HTML if required.<br />
<strong>Block:</strong> The block to call through layout for the above controller.</p>
<p>Now lets be descriptive.</p>
<p>If you want to show a loader while request is being processed just add the following whereever you like in the phtml page.First fetch the Javascript.</p>
<pre class="brush: jscript;">
&lt;script src=&quot;&lt;?php echo $this-&gt;getJsUrl() ?&gt;mage/adminhtml/loader.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>Then echo the loader which pops up. This loader will be similar to that of the admin.</p>
<pre class="brush: xml;">
&lt;div id=&quot;loadingmask&quot; style=&quot;display: none;&quot;&gt;
&lt;div class=&quot;loader&quot; id=&quot;loading-mask-loader&quot;&gt;&lt;img src=&quot;&lt;?php echo str_replace(&quot;index.php/&quot;,&quot;&quot;,$this-&gt;getUrl()) ?&gt;skin/adminhtml/default/default/images/ajax-loader-tr.gif&quot; alt=&quot;&lt;?php echo $this-&gt;__('Loading...') ?&gt;&quot;/&gt;&lt;?php echo $this-&gt;__('Loading...') ?&gt;&lt;/div&gt;
&lt;div id=&quot;loading-mask&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Now to Call Ajax, use the following lines</p>
<pre class="brush: jscript;">

/*Please note that the URL is created in reloadurl. Also see that the response text will be echoed in div with id=output-div*/

var reloadurl = '&lt;?php echo $this-&gt;getUrl('router/controller/action') ?&gt;';
Element.show('loadingmask');
new Ajax.Request(reloadurl, {
method: 'post',
parameters: &quot;Params_Here&quot;,
onComplete: function(transport) {
Element.hide('loadingmask');
$('output-div').innerHTML = &quot;&quot;;
$('output-div').innerHTML = transport.responseText;

}
});
</pre>
<p>After the Ajax Request is made it goes to your controller&#8217;s action, which in turn sees to your layout as follows:</p>
<pre class="brush: php;">
class Namespace_module_frontendController extends Mage_Core_Controller_Front_Action
{
public function actionAction(){
$this-&gt;loadLayout()-&gt;renderLayout();
}
}
</pre>
<p>And here is the main part in layout where I spent most of my time in. Since in layout we will have to define reference where the html will echo (Most of the times), i got stuck here, because i need to echo the output on the div with id output-div not in any reference.And the trick is to name the layout as root and output as html. Like the following:</p>
<pre class="brush: xml;">

&lt;module_controller_action&gt;
&lt;block type=&quot;module/block&quot;  name=&quot;root&quot; output=&quot;toHtml&quot;  template=&quot;module/template.phtml&quot;/&gt;
&lt;/module_controller_action&gt;
</pre>
<p>You are done now! What ever you write or echo in phtml file you will see populated in the DIV. Now you can treat block as normally as you do before.</p>
<p>Happy Coding!!
<div style="margin-top: 15px; font-style: italic">
<p><strong>&copy;</strong> <a href="http://subesh.com.np/">Subesh Pokhrel&#039;s Blog &#8211; Magento Development Tips,PHP,Google Maps</a></p>
</div>
<hr /><small>Copyright &copy; 2010<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. </small>
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fsubesh.com.np%2F2009%2F11%2Fworking-with-ajax-in-magento%2F" layout="standard" show_faces="true" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/11/working-with-ajax-in-magento/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Ajax | Subesh Pokhrel&#039;s Blog - Magento Development Tips,PHP,Google Maps</title>
		<link>http://subesh.com.np/2008/07/ajaxified-file-uploader-using-iframe/</link>
		<comments>http://subesh.com.np/2008/07/ajaxified-file-uploader-using-iframe/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 12:00:39 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fileupload]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=66</guid>
		<description><![CDATA[Today, while writing a code for AJAX file uploader, I was trying to do with [wiki]SALAJAX[/wiki]. But, with SALAJAX I could not manage to send the headers for $_FILES. So I thought of an alternative. And the alternative was to load the action page of the form on [wiki]IFrame[/wiki], whose display would be hidden and [...]]]></description>
			<content:encoded><![CDATA[<p>Today, while writing a code for AJAX file uploader, I was trying to do with [wiki]SALAJAX[/wiki]. But, with <strong>SALAJAX</strong> I could not manage to send the headers for <strong>$_FILES</strong>. So I thought of an alternative. And the alternative was to load the action page of the form on [wiki]IFrame[/wiki], whose display would be hidden and the work for uploading the file will be done on the background without refreshing the page. Yeha.. Its not [wiki]AJAX[/wiki], but it gives a user the feel of asynchronous working on the page. So, my code is <strong>Asynchronous Feel Without Javascript and XML (AFWJAX)</strong>. What do think about this?<br />
So, Here&#8217;s the code.The code below is for the form.</p>
<pre class="brush: xml;">
&lt;form action=&quot;iframeinc.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; id=&quot;uploadform&quot; target=&quot;iframe&quot; name=&quot;uploadform&quot;&gt;
 File:
  &lt;input name=&quot;pic&quot; type=&quot;file&quot; id=&quot;pic&quot; style=&quot;margin-right:50px;&quot; /&gt;
  &lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Upload&quot; &gt;&lt;br /&gt;
&lt;iframe name=&quot;iframe&quot; src=&quot;iframeinc.php&quot; width=&quot;200&quot; height=&quot;500&quot; style=&quot;display:none;&quot;&gt; &lt;/iframe&gt;
&lt;/form&gt;
</pre>
<p><span id="more-66"></span></p>
<p>You can see on <strong>#1</strong> the action of the form is <strong>iframeinc.php</strong>. The code for this page is given below. There are some other things you should remember. Like the <strong>target</strong> for the form is set <strong>iframe</strong>, whose <strong>display</strong> is set <strong>none</strong> so that it is not seen.  And this iframe is the of the iframe created on <strong>#6</strong>, whose source is the <strong>iframeinc.php</strong>. Now here&#8217;s its code.</p>
<pre class="brush: php;">
&lt;?php
if($_POST){

	// $newname is the new path/name of the file on the server.
	$copied = copy($_FILES['pic']['tmp_name'], &quot;$newname&quot;);

}
?&gt;
</pre>
<p>Remember to set <strong>$newname</strong> value before running this. At first run you may see this as a regular post script, but try to reload with f5 or reload button of your browser, you will not be asked to retry or resend the post header. So, there are own ways of catching your nose.<br />
<a href="http://subeshexamples.googlecode.com/files/upload.rar"><strong>[Download Source]</strong></a>
<div style="margin-top: 15px; font-style: italic">
<p><strong>&copy;</strong> <a href="http://subesh.com.np/">Subesh Pokhrel&#039;s Blog &#8211; Magento Development Tips,PHP,Google Maps</a></p>
</div>
<hr /><small>Copyright &copy; 2010<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. </small>
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fsubesh.com.np%2F2008%2F07%2Fajaxified-file-uploader-using-iframe%2F" layout="standard" show_faces="true" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2008/07/ajaxified-file-uploader-using-iframe/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
