Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda