I try to create a select menu using Ajax, but not work. I use matrix template with Joomla 5.1.2
this result in front end:
My code in article:
Code: Select all
<form action="" method="post"><strong>DETTAGLI SPESE CONTO</strong>
<select id="state">
<option value="NA">Seleziona anno</option>
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "SELECT idanno FROM #__anno";
$db->setQuery($query);
$results = $db->loadAssocList();
if($results != null){
foreach ( $results as $print ){
echo '<option>'.$print['idanno'].'</option>';
}
}
else
{
echo "Error table anno";
}
?>
</select>
</form>
<div id="results"> </div>
Code: Select all
<script type="text/javascript">
var jQueryRepresentatives = jQuery.noConflict();
jQueryRepresentatives(document.body).on('change','#state',function(){
jQueryRepresentatives.ajax({
type: 'GET',
url: "localhost/progetti/dilerooms/index.php/dashboard",
success:function(data){
jQueryRepresentatives('#results').html(data);
},
error:function(){
jQueryRepresentatives('#results').html('<p>error '+jQueryRepresentatives('#state').val()+'</p>');
}
});
});
</script>
because error:function()
Thank you