0
I have the page that returns an Ajax request.
When executing it by passing the parameters: grupoCategoria=1&subCat=302
in the expression: if($dados_Subcategorias[codigo_subcategoria] == $_GET[subCat])
is made the option
as slected
.
On this page it works, but on the page that makes the request to this page it does not bring the data that enters the if
only the data of else
.
<?php
$grupoCategoria = $_GET['grupoCategoria'];
$sql = "SELECT codigo_categoria,codigo_subcategoria,nome_subcategoria,descricao_subcategoria
FROM Subcategorias WHERE codigo_categoria=$grupoCategoria and codigo_subcategoria in(302,308,309) order by nome_subcategoria ";
$res_Subcategorias = mysql_query($sql, $con_local);
$num_Subcategorias = mysql_num_rows($res_Subcategorias);
if($num_Subcategorias>0){
echo "<select name='Subcategorias' id='Subcategorias' >";
echo "<option value=''>Selecione...</option>";
for($j=0;$j<$num_Subcategorias;$j++){
$dados_Subcategorias = mysql_fetch_assoc($res_Subcategorias);
// echo "<option value='$dados_Subcategorias[codigo_subcategoria]'>".utf8_encode($dados_Subcategorias[nome_subcategoria])."</option>";
if($dados_Subcategorias[codigo_subcategoria] == $_GET[subCat]){
echo "<option selected='selected' value='$dados_Subcategorias[codigo_subcategoria]'>".utf8_encode($dados_Subcategorias[nome_subcategoria])."-".$dados_Subcategorias[codigo_subcategoria]."</option>";
}
else{
echo "<option value='$dados_Subcategorias[codigo_subcategoria]'>".utf8_encode($dados_Subcategorias[nome_subcategoria])."-".$dados_Subcategorias[codigo_subcategoria]."</option>";
}
}
echo "</select>";
}
?>
How is your js code to perform asynchronous call?
– Oeslei
Hello, give a var_dump($dados_Subcategories) or print_r($dados_Subcategories) and see if this brings the data you expect to come from your query.
– Alex Juchem
<script> Function searchSubCategories(){ var groupCategory = $('#groupCategory'). val(); if(groupCategory){ //Alert('getSubCategories.php?groupCategory='+groupCategory); var url = 'getSubCategories.php? groupCategory='+groupCategory; $.get(url, Function(dataReturn) { $('#checkSubcategories').html(dataReturn); }); } } </script>
– luis ricardo
Luis, welcome to [en.so]. I reversed its last edition because here we do not put the title of "closed" to inform that our problem has been solved, and yes we mark as accepted the answer that solved our problem. See more in: How and why to accept an answer?, take advantage and make a [tour] by the site.
– Math