HI , sorry for english , in my form , i want populate a select by searching value inserting a substring ( with like select ),
This is Jquery code :
Code:
<script>
$( document ).ready(function() {
var stato=$("#id_class_stato_agenda_id option:selected").val();
$("#id_class_stato_agenda_id").change(function() {
var stato=$("#id_class_stato_agenda_id option:selected").val();
if(stato=='1' || stato=='2'){
$("#id_class_clienti_id").val('');
}
console.log(stato);
});
$("#ricerca_cliente").click(function(){
var ragione_sociale_getted = $("#ragione_sociale").val();
var csrfName = '<?php echo $this->security->get_csrf_token_name(); ?>';
var csrfHash = '<?php echo $this->security->get_csrf_hash(); ?>';
$.ajax({
type: "POST",
url: "<?=base_url()?>index.php/clienti/ricerca_clienti_select",
data: {
ragione_sociale:ragione_sociale_getted ,
csrfName:csrfHash
},
dataType: "html",
success: function(msg)
{
$("#id_class_id_cliente").html(msg);
},
error: function()
{
alert("Chiamata fallita, si prega di riprovare...");
}
});
});
});
</script>
This is the controller :
this is the controller function :
PHP Code:
public function ricerca_clienti_select() {
$csrf = $this->security->get_csrf_hash();
$this->output->set_content_type('application/json')->set_output(json_encode(array( 'csrf' => $csrf)));
if (!empty($this->input->post('ragione_sociale'))) {
$ragione_sociale = $this->input->post('ragione_sociale');
$lista = $this->clienti_model->recupera_by_name($ragione_sociale);
foreach ($lista->result() as $row) {
echo "<option value='" . $row->id_clienti . " '>";
echo $row->ragione_sociale;
echo "</option> ";
}
}
}
This is error :
jquery-3.2.1.js:9566 POST
https://www.mysite.it/gest/index.php/cli...nti_select 403 (Forbidden)
XHR failed loading: POST "https://www.mysite.it/gest/index.php/clienti/ricerca_clienti_select".