<?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>Subooa Studios Blog &#187; ajax</title>
	<atom:link href="http://blog.subooa.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.subooa.com</link>
	<description>Custom development by Chris Duell aka duellsy</description>
	<lastBuildDate>Wed, 28 Jul 2010 03:57:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ajax in Joomla with jQuery</title>
		<link>http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/</link>
		<comments>http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 07:11:36 +0000</pubDate>
		<dc:creator>Chris Duell</dc:creator>
				<category><![CDATA[Ajax & Javascript]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blog.subooa.com/?p=308</guid>
		<description><![CDATA[Sometimes you need Joomla to give you nothing but the components output. No template, no styling, nothing. Just the output. This article shows you how to do this, and tie it in with an Ajax call.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fjoomla-coding%2Fajax-in-joomla-with-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fjoomla-coding%2Fajax-in-joomla-with-jquery%2F&amp;source=duellsy&amp;style=normal&amp;service=bit.ly&amp;hashtags=ajax,component,joomla,jquery" height="61" width="50" /><br />
			</a>
		</div>
<p>This article came about while I was building a custom Joomla component at work, the component required a multi step form that stayed on the same page. So data needed to be grabbed from the database and displayed on the screen as the user was filling in the form.</p>
<p>I wont go into the details of making a custom component as that is outside the scope of this article, more information on that can be found <a href="http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1">here</a>, instead we&#8217;ll just grab an article assuming that it belongs to a menu and has the Itemid of 10 (you can call absolutely any component you like, as long as you know the non SEF link to the page you are after).</p>
<p>First of all we need to load jQuery, we&#8217;ll load this from Googles server to reduce the load on our own server</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p308code1'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3081"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p308code1"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>We&#8217;ll also need to setup a new file in the /templates/system/ folder called barebones.php that will be called when we make our Ajax calls instead of the normal template so that the data returned doesn&#8217;t include the main template, css, javascript etc. Create the file, and enter in the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p308code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3082"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p308code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * @copyright	Copyright (C) 2009 subooa.com. All rights reserved.
 * @license	GNU/GPL, see LICENSE.php
 * @author	Chris Duell (subooa.com)
 * barebones is a stripped template by subooa. 
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// no direct access</span>
<a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'_JEXEC'</span> <span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Restricted access'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>jdoc<span style="color: #339933;">:</span><span style="color: #b1b100;">include</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;component&quot;</span> <span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

<p>Now to making the Ajax call, you will need a place to put the data once it is loaded, so create a div with the id of &#8220;ajax_here&#8221;.</p>
<p>Using jQuery, the Ajax call is pretty striaght forward:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p308code3'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3083"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p308code3"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	jQuery.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
		url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;index.php&quot;</span><span style="color: #339933;">,</span>
		data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;?Itemid=10&amp;tmpl=barebones&quot;</span><span style="color: #339933;">,</span>
		success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>html<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#ajax_here&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>html<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Quickly stepping through this, we are making a call to index.php and requesting the article associated with Itemid 10, and after the data is received adding it to the div that we created earlier that has the id of &#8220;ajax_here&#8221;. But most importantly, we explicitly call the &#8220;barebones&#8221; template so the data returned and entered into the div is ONLY the output for the component, nothing more.</p>
<p>I highly recommend using <a href="http://getfirebug.com/">Firebug </a>as you are developing and testing this so that you can see if the Ajax calls are being correctly made, and the expected results are being returned. </p>
<p>This article is quite basic on purpose, however if you would like more information just leave a comment.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/&amp;title=Ajax+in+Joomla+with+jQuery" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/&amp;title=Ajax+in+Joomla+with+jQuery" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/&amp;title=Ajax+in+Joomla+with+jQuery&amp;desc=Sometimes%20you%20need%20Joomla%20to%20give%20you%20nothing%20but%20the%20components%20output.%20No%20template%2C%20no%20styling%2C%20nothing.%20Just%20the%20output.%20This%20article%20shows%20you%20how%20to%20do%20this%2C%20and%20tie%20it%20in%20with%20an%20Ajax%20call." rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/&amp;title=Ajax+in+Joomla+with+jQuery" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/&amp;title=Ajax+in+Joomla+with+jQuery" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Ajax+in+Joomla+with+jQuery+-+http://bit.ly/2kkmFb&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fjoomla-coding%2Fajax-in-joomla-with-jquery%2F","http:\/\/docs.joomla.org\/Developing_a_Model-View-Controller_Component_-_Part_1","http:\/\/getfirebug.com\/","http:\/\/twitter.com\/home?status=Ajax+in+Joomla+with+jQuery+-+http:\/\/bit.ly\/2kkmFb&amp;source=shareaholic"];var wordpress_toolbar_url = "";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2Jsb2cuc3Vib29hLmNvbS9kZXZlbG9wbWVudC9qb29tbGEtY29kaW5nL2FqYXgtaW4tam9vbWxhLXdpdGgtanF1ZXJ5Lzx3cHRiPkFqYXggaW4gSm9vbWxhIHdpdGggalF1ZXJ5PHdwdGI%2BaHR0cDovL2Jsb2cuc3Vib29hLmNvbTx3cHRiPlN1Ym9vYSBTdHVkaW9zIEJsb2c%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://blog.subooa.com/development/joomla-coding/ajax-in-joomla-with-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
