3

For some time now I have been working with Joomla, and now I am working with a version 3.1.5. I often make my own PHP scripts to use for AJAX callbacks and other things. I put them in a folder called scripts which isn't part of the normal Joomla installation.

Because of this I have to use some configuration code to get the scripts to work well when accessing them from Joomla. I use this code:

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

/* Create the Application */
$mainframe = JFactory::getApplication('site');

Recently I am trying to call this script for AJAX and I am getting this following error:

404 (Category not found)

The only reason I can think of for this is that Joomla things that the user doesn't have privileges to read the script because of some reason to do with a category? I am not sure, and I am looking for some help. I have created any categories for this Joomla installation and I don't use them.

migrated from stackoverflow.com May 9 '14 at 14:59

This question came from our site for professional and enthusiast programmers.

  • Have you moved your custom PHP file or the location of your Joomla site to a different folder? – Lodder May 8 '14 at 14:19
  • no, the AJAX call still works from another page on the same site, with the same path to this script. – jeffery_the_wind May 8 '14 at 15:38
  • What all data are you submitting to this page with the AJAX? Sounds like you likely have an input variable set that joomla is trying to process by default. – David Fritsch May 9 '14 at 16:18
  • I've got the same problem with 100% external files, so they don't contain any Joomla file includes. EDIT: Try to delete the .htaccess, and see what happens. Actually, my file had an internal server error... – user380 May 9 '14 at 19:59
  • What does the AJAX URL look like? What params are you sending? – Mathew Lenning May 12 '14 at 1:30
2

When you call independent PHP scripts for AJAX callbacks, you have to check how they live along the regular Joomla! site.

In a common Apache-Joomla setup, first .htaccess applies several rules to define security restrictions, SEF processing, etc. After that, index.php takes control, initializes the CMS, routes the call to the right component, and finally generate the output.

In your case, it seems Apache is delegating the call to com_content component, instead of calling your script.

0

I guys. In my case, I was having this because the 'task' was not being passed to the page. I had a hidden form field that had

<input type="hidden" name="jform[task]" value="myCustomTask">

instead of

<input type="hidden" name="task" value="myCustomTask">

That was mainly because I had the task in the a form's XML file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.