0
Good morning Everybody, everything’s fine?
I have been days trying to return a value from my view to my controller using codeigniter. But I don’t want refresh to happen on the page.
So decide to use ajax, but in my query either it comes with the html code of my page or it gives this error:
{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
My HTML:
<form real="form" id="form" nome="form" method="post" action='<?= base_url("index.php/welcome");?>'>
<select class="form-control" name="selectUser" id="seletor">
<option value='<?= $_SESSION["nome"]?>' >Only me</option>
<option value="Trello">Team</option>
</select>
</form>
My controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$nome = $this->input->post('valor');
var_dump($nome);
$this->load->model('testemodel');
$verifica= $this->testemodel->verifica($nome);
$data['nomecliente'] = $verifica['nome_cliente'];
$data['horatotal'] = $verifica['hora_total'];
$data['atividade'] = $verifica['nome_atividade'];
$this->load->view('test', $data);
}
My Javascript:
$("#seletor").change(function(){
var value = $("#seletor").val();
$.ajax({
url: 'welcome/index',
type: 'POST',
dataType: "json",
data: {"valor" : value},
success: function(data){
console.log(data);
},
error: function(data){
console.log(data);
}
});
});
I hope you can help me. I will be very grateful!
You are giving this error here on the console.log(); {readyState: 4, getResponseHeader: ?, getAllResponseHeaders: ?, setRequestHeader: ?, overrideMimeType: ?, ...}
– Diêgo Correia de Andrade
Take a look at the browser console in the network tab if your request is returning correctly
– Otto
You saved brother! Thank you very much!
– Diêgo Correia de Andrade