Posts Tagged Joomla
Ajax in Joomla Component
Posted by Link Sutra in Joomla on May 26, 2010
If you already have your own joomla component then it is fine otherwise create new one for yourself within minute. Joomla Component Creator
Lets assume we have component “ajaxcall” and we are making ajaxcall from “com_ajaxcall\views\ajaxcall\tmpl\default.php” file.
We will make ajax call to the format “ajaxcallformat” (i.e. view.ajaxcallformat.php)
javascript code in “com_ajaxcall\views\ajaxcall\tmpl\default.php”
<script type="text/javascript">
function AjaxCall(name)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function statecall()
{
if(httpxml.readyState==4)
{
var resp=httpxml.responseText;
alert(resp);
}
}
var url="index.php?option=com_ajaxcall&view=ajaxcall&format=ajaxcallformat";
var params="name="+name;
httpxml.onreadystatechange=statecall;
httpxml.open("POST",url,true);
//Send the proper header information along with the request
httpxml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpxml.setRequestHeader("Content-length", params.length);
httpxml.setRequestHeader("Connection", "close");
httpxml.send(params);
}
</script>
AjaxCall in “com_ajaxcall\views\ajaxcall\default.php”
<label>Name:</label>
<input type="text" name="name" id="name">
<input type="button" value="Submit"
OnClick="AjaxCall(document.getElementById('name').value);">
view.ajaxcallformat.php will be in (i.e. com_ajaxcall\views\ajaxcall ) folder.
<?php
/**
* Joomla! 1.5 component AjaxCall
*
* @version $Id: view.html.php 2010-05-25 15:58:28 svn $
* @author govind dubey
* @package Joomla
* @subpackage AjaxCall
* @license GNU/GPL
*
* AjaxCall
*
* This component file was created using the Joomla Component Creator by Not Web Design
* http://www.notwebdesign.com/joomla_component_creator/
*
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.view');
/**
* HTML View class for the AjaxCall component
*/
class AjaxcallViewAjaxcall extends JView {
function display($tpl = null) {
}
}
echo $_POST['name'];
?>