Ajax script does not work

Asked

Viewed 31 times

1

I am trying to fill a combo box (cities) in the change of another combo box (states), and I tried to fill this out via AJAX, but the script I made is not running, if anyone can help me, I thank you from now

            <div class="row" onload=""?>
            <div class="input-field col s12 l6"> 

              <select name="Ped_estado" id ="estado" class = "browser-default"> 

                <?php
                    $connect = mysqli_connect('localhost:3306','root','');
                    $db = mysqli_select_db($connect,'ibico');
                    $sql_code = mysqli_query($connect,"SELECT Id, Nome, UF FROM Estado order by Nome ASC") or die("erro ao selecionar");
                    foreach ($sql_code as $estado) 
                    {
                    echo'<option value ="'.$estado['Id'].'">'.$estado['Nome'].'</option>';

                    }
                ?> 
           </select>
            </div>
          </div>                           
          <!-- <label for="estado">Estado</label> -->           
            <div class="input-field col s12 l6">
                <div class="row">
             <select name="Ped_municipio" id="municipios" class = "browser-default">

             <script>
                    $("#estado").on("change", function(){

                    var idEstado = $("#estado").val();
                    $.ajax({
                        url:'../ibico/php/carregaMunicipios.php';   
                        type: 'POST',
                        data:{id:idEstado},
                        beforeSend: function(){
                            $("#municipios").html("Carregando..");
                        },
                        success: function(data)
                        {
                            $("#municipios").html(data);
                        }
                        error: function(data)
                        {
                            $("#municipios").html("Houve um erro ao carregar !");
                        }
                    })

                    });
            </script>
  • Which error is triggered?

  • Syntaxerror: Unexpected token;

  • 1

    url:'../ibico/php/carregaMunicipios.php'; change the semicolon at the end of that line by a comma

  • exact as Artur quoted.

  • That’s right, vlw :D

  • People now accused other error Uncaught Syntaxerror: Unexpected Identifier

Show 1 more comment

1 answer

0


You have a syntax error in your Javascript code.

In your script, simply remove the semicolon from that line:

url: '../ibico/php/carregaMunicipios.php';

Staying, then:

url: '../ibico/php/carregaMunicipios.php'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.