Problem generating content via Jquery

3

I have a problem that depending on the text selected in the first check box it does not load the years relative to it in the database. Only when text loaded in the first box has no space does jquery work.

* Follows the file with the "gera_html.php" checkboxes *

<html>
<head>
<title>Gerador Planos de Ensino</title>
<link rel="stylesheet" media="screen" href="./css/styles.css" > 
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="./js/ver_selects.js" type="text/javascript">
</script>
<script type="text/javascript">
    $(document).ready(function(){

        $('#departamentos').change(function(){
            $('#anos').load('anos.php?departamentos='+$('#departamentos').val() );

        });
    });
</script>   
</head>
<?php

  include "valida_cookies.inc";
  require("connect.php");

?>
<body>
<form class="cad_admin" method="GET" action="anos.php" autocomplete="on" >
<ul>
<h2>Gerador Planos de Ensino</h2>
<li>
<li><label>Escolha um Departamento</label>
<select name="departamentos"  id="departamentos" >
<?php
require("connect.php");
$depto_result=mysql_query("SELECT DISTINCT DepartamentoDoResponsavel FROM  responsavel ORDER BY    DepartamentoDoResponsavel ASC");
echo "<option value='00'>".'Escolha um departamento'."</option>";
while($row = mysql_fetch_array($depto_result)){
echo "<option>".$row['DepartamentoDoResponsavel']."</option>";
}
mysql_close();
?>
</select></li>      

</select></li>      
<li><label>Ano</label>
<select name="anos" id="anos">
    <option value="00">Escolha um Ano</option>
</select></li>
<li>
 <button class="submit" type="submit">Gerar</button>
</li>
</li>
</ul>
</form>
</body>
</html>

And here the anos.php being called in jquery     

$departamento = $_GET['departamentos'];
echo $departamento;
require('connect.php');

     $sql = "SELECT DISTINCT AnoDeAplicacao FROM planodeensino 
    WHERE planodeensino.DepartamentoPorExtenso = '$departamento'";

$result = mysql_query($sql);
echo "<option value='0'>".'Escolha um Ano'."</option>";

while($linha = mysql_fetch_array($result) ){
    echo "<option>".$linha['AnoDeAplicacao']."</option>";
}
mysql_close();

?>
    
asked by anonymous 05.02.2014 / 20:48

2 answers

1

I think the param method of jQuery will help you: link

Try changing the line that calls the load of jQuery by leaving it like this:

$('#anos').load('anos.php?' + $.param({ departamentos: $('#departamentos').val() }) );

Another thing: your application is using ISO-8859-1, but Ajax is UTF-8. To resolve this, change the first line of the script "anos.php" to:

$departamento = utf8_decode($_GET['departamentos']);
    
05.02.2014 / 21:29
0

In your query, try to use LIKE %% instead of comparison, so I understand, I think you can solve it:

"SELECT DISTINCT AnoDeAplicacao FROM planodeensino WHERE planodeensino.DepartamentoPorExtenso LIKE %$departamento%"
    
05.02.2014 / 20:52