php – Problem generating content via Jquery


I have a problem that depending on the text selected in the first selection box it doesn't load the years related to it in the database. Only when the text loaded in the first box has no space does jquery work.

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

<title>Gerador Planos de Ensino</title>
<link 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 type="text/javascript">

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


  include "";

<form class="cad_admin" method="GET" action="anos.php" autocomplete="on" >
<h2>Gerador Planos de Ensino</h2>
<li><label>Escolha um Departamento</label>
<select name="departamentos"  id="departamentos" >
$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>";

<select name="anos" id="anos">
    <option value="00">Escolha um Ano</option>
 <button class="submit" type="submit">Gerar</button>

And here the anos.php being called in the 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(); ?>


I think jQuery's param method will help you:

Try changing the line that calls the jQuery load to make it look like this:

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

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

$departamento = utf8_decode($_GET['departamentos']);
Scroll to Top