1

I'm using an ajax call that hits the immediate function fine, and then returns a dummy value via dump(). However, when I change it to call another function and get my data rather than using the dummy value, I'm getting a 500 error.

In Helper.php, This returns the value with a code 200:

public static function getStoresByZipAjax(){

    $input = JFactory::getApplication()->input;
    $zip  = $input->get("zip");

    dump($zip);

    //return $this->getStores($zip);
}

However, when I comment out the dump and reinstate the function call, it fails with a 500:

public static function getStoresByZipAjax(){

    $input = JFactory::getApplication()->input;
    $zip  = $input->get("zip");

    //dump($zip);

     return $this->getStores($zip);
}

public static function getStores($zip){
    $test = $zip;

    dump($test);
}

Here is my mod_hunter_maps_dev.php file:

<?php 
 //check joomla calling
defined('_JEXEC') or die;
require_once dirname(__FILE__) . '/helper.php';

$test = modHunterMapsDevHelper::getStores();


require JModuleHelper::getLayoutPath('mod_hunter_maps_dev', $params->get('layout', 'default'));
?>

What am I doing wrong here?

AJAX call for reference:

jQuery.ajax({
   type: 'GET',
   url: "<?php echo JURI::base() . "index.php?option=com_ajax&module=hunter_maps_dev&method=getStoresByZip&zip="?>"  +zip+ "&format=json",
   success:function(data){
       console.log('success');
   },
   error: function(xhr, status, error) {
       alert(xhr.responseText);
   }
 });
2

The fatal error will be: "PHP Fatal error: Using $this when not in object context"

You need to change

return $this->getStores($zip);

to

return self::getStores($zip);
1
  • Yes, that was the issue. Thanks!
    – Geoff_S
    Sep 24 at 14:10

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.