Ajax on codeigniter 4 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Ajax on codeigniter 4 (/showthread.php?tid=76097) |
Ajax on codeigniter 4 - Alexcodeig - 04-14-2020 Hey guys, how are you? I´m trying to use ajax on my ci4 application, but is not working. I want the select boxes changing according the countries and states selected. Please, some help? .js ________ $( ".pais" ).change(function() { var id_pais= $("#pais").val(); var base_url= "<?php echo base_url();?>"; $.post(base_url+'/index.php/estado/getEstado', { id_pais : id_pais },function (data) { $("#estado").html(data); $("#estado").removeAttr('disabled'); }); }); ________ Model ________ namespace App\Models; use CodeIgniter\Model; class EstadoModel extends Model { //Atributos de configuração protected $table='estado'; protected $primaryKey= 'id'; //Metodo GET public function getEstado($id_pais){ return $this->asArray()->where(['pais' => $id_pais])->first(); } } ________ Controller ________ use App\Models\EstadoModel; class Estado extends BaseController { public function getEstado() { $id_pais= $this->request->getVar('id_pais'); $model = new EstadoModel(); echo $model->getEstado($id_pais); } } ________ Note: Error code 403 to ajax response (I see this in the inspect element on my browser - Network). RE: Ajax on codeigniter 4 - ci4hell - 04-15-2020 (04-14-2020, 06:33 AM)Alexcodeig Wrote: Hey guys, how are you? add csrf token in ajax data. RE: Ajax on codeigniter 4 - InsiteFX - 04-16-2020 Also you should use getPost instead of getVar. |