如何从jquery传递变量到控制器

how to pass variable to controller from jquery

本文关键字:变量 控制器 jquery      更新时间:2023-09-26
$(function(){
$('#textb').keypress(function (e) {
 var key = e.which;
 var messag=document.getElementById('textb').value;
 if(key == 13) 
  {
 window.location.href = "refresh/?mesag=" + messag;
  }
});
});

如何在codeigniter中将变量从视图传递给控制器

视图:

 if(key == 13){
    $.post( "route/to/post/to", { id: "2"} );
 }

控制器:

if($this->input->post("id")){
    echo $this->input->post("id");
}

这将返回2