Send request via ajax php

Asked

Viewed 55 times

0

I would like to know how I make a request via ajax in real time, basically it is to popular a select of cities, more when I have run the code his modal simply does not open, follow the code to analyze.

in the controller

 $id = $_POST;            

        $query = $this->db->query(" SELECT * FROM estados ")->result();
         $query_cidades = $this->db->query(" SELECT * FROM cidades WHERE cidades.cod_estado = $id")->result();

            $data = [
        'revendedor' => Model\Revendedores::find($cod_revendedor),
                    "estados" => $query,
                    "cidades" => $query_cidades
    ];

    $this->load->view('revendedores/_form', $data);

in the view

  $('.escolha').on('click', function(){

                        var id_box = $( this ).data('id-box');

                       $.ajax({
                          url: "sua url",
                          method: "POST",
                          dataType: "json",
                          data:{
                            id : id_box,

                          }
                        }).done(function( data ) {
                            $('.escolha').html(data.id);
                        });
                    });
  • vc already has an error in the first line, you are not getting the id of the post $id = (int)$_POST['id'];

  • thank you I will test here, put the resolution ok

No answers

Browser other questions tagged

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