F.schettino
Italian
I use Javascript on blur of an element to get a value from database using a function in user_ajax.php.
It doesn't work; alert(r) is blank.
If I modify last PHP statement from "echo $CAP_Comune;" to
What is wrong? Why 'Codice_Comune' is not assigned to $cod_comune?
Can someone help me, please?
Code:
var elemento_Comune = Fabrik.getBlock('form_20').elements.get('fabrik_nominativi___Citta_Residenza');
var Codice_Comune = elemento_Comune.get('value');
var CAP_Comune='';
var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=CAP_da_Citta&Codice_Comune=" + Codice_Comune;
new Request(
{url:url,
method: 'get',
onComplete: function(r) {alert(Codice_Comune); alert(r)}
}).send();
PHP:
<?php
defined('_JEXEC') or die('Restricted access');
class UserAjax
{
public function CAP_da_Citta()
{
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$CAP_Comune = ' ';
$app = JFactory::getApplication();
$input = $app->input;
$cod_comune = $input->get('Codice_Comune', ' ');
$query="SELECT CAP FROM fabrik_comuni WHERE Codice_Comune=" . $cod_comune;
$db->setQuery($query, 1, 0);
$CAP_Comune = $db->loadResult();
echo $CAP_Comune;
}
}
It doesn't work; alert(r) is blank.
If I modify last PHP statement from "echo $CAP_Comune;" to
"echo $cod_comune;"
alert(r) displays:undefined
so, the query cannot work.What is wrong? Why 'Codice_Comune' is not assigned to $cod_comune?
Can someone help me, please?