Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
send request from Javascript in default.php into helper file, Joomla

I have a fully working module in Joomla, but I'm struggling with the last piece which is sending a value from Javascript in my default.php file into the helper file, where it will be used in a sql query and return the results. Everything up to that point works perfectly and if I just hardcode the value in SQL it returns what I need to the default.php file.

My issue is that when the JS function getApi is called and I set an input value to 12345, I also want to send that value of 12345 into my helpepr function called getStores

How can I properly send this value and have it returned in real time asynchronously?

helper.php

<?php

class modTestHelper
{

public static function getStores($zip)
{
    $db = JFactory::getDBO();
    $user = JFactory::getUser();
    
    $app = JFactory::getApplication();
    $lang = JFactory::getLanguage();
    $date = JFactory::getDate();
    $now = $date->format('Y-m-d');
    
    
    $query = 'SELECT
            name,
            phone,
            address,
            city,
            state,
            zip,
            country,
            url,
            logo,
            lat,
            lng

            from #__loc_table
            where published = 1
            AND zip ="'.$zip.'"';
    
    
    $db->setQuery($query);
    $item=$db->loadObjectList();
    $stores = [
        'type' => 'FeatureCollection',
        'features' => array_map(function($i) {
            return [
                'type' => 'Feature',
                'geometry' => [
                    'type' => 'Point',
                    'coordinates' => [
                        $i->lat,
                        $i->lng
                    ]
                ],
                'properties' => [
                    'storeImage' => $i->logo,
                    'storeName' => $i->name,
                    'phoneFormatted' => $i->phone,
                    'address' => $i->address,
                    'city' => $i->city,
                    'country' => $i->country,
                    'postalCode' => $i->zip,
                    'state' => $i->state
                ]
            ];
        }, $item)
    ];                      
            
    return json_encode($stores);
}
}

mod_test.php

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

$test = modTestHelper::getStores();


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

default.php

    <script type="text/javascript">

          function getApi() {
             var zip = '12345';
             div.value = var;
          }

     </script>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda