If your are a Joomla developer sometimes you encounter a task which needs to produce jQuery Ajax call in order to add some additional content to a Joomla article page or just to make some operation in a background. In this case this article will help you to implement this feature on a page.
So first create an empty file called: view.ajax.php and upload it to YOUR_SITE_HOME/components/com_content/views/article folder Add the php code below into this file:
get(‘id’);
$task = JRequest::getString(‘task’);
switch( $task ){
case “getArticles”:
$this->_getArticles();
break;
}
jexit();
}
public function _getArticles(){
$query = “SELECT title FROM #__content WHERE catid = 11 ORDER BY id DESC”;
$articlesList = JFactory::getDBO()->setQuery($query)->loadObjectList();
$html = “”;
foreach( $articlesList as $article ){
$html .= ‘
‘;
}
echo ‘
‘;
jexit();
}
}
?>
Then create a java script file with this JS script and add it to your page HEADER or just add it to your article php source:
Download Sample : https://www.mysite4u.net/images/mysite4u/examples/ajax-example-src.zip
Reference : https://www.mysite4u.net/joomla-articles/jquery-ajax-call-joomla.html