[英]How to get one or two of data value in Controller Codeigniter when using AJAX Post
can someone help me with my code, i have AJAX json type POST and i wanto to get one or two of data send to controller in codeigniter, i wanto to add conditional function where the data from json.有人可以用我的代码帮助我吗,我有 AJAX json 类型的 POST,我想将一两个数据发送到 codeigniter 中的 controller,我想添加条件 function,其中数据来自 8817595863040
My JSON我的 JSON
$('#add_people').submit(function(e){
e.preventDefault();
var id_people = $('#id_people').val();
var name_people = $('#name_people').val();
var phone_people = $('#phone_people').val();
$.ajax({
type : "POST",
url : "<?php echo base_url('add_people_data')?>",
dataType : "JSON",
data : {id_people:id_people , name_people:name_people, phone_people:phone_people},
success: function(data){
$("#show_people").html('<img src="assets/img/user/spinner.gif"> <h4>Loading data...</h4>');
$('#modal-add_people').modal('hide');
$('.modal-backdrop').remove();
$('[name="id_people"]').val("");
$('[name="name_people"]').val("");
$('[name="phone_people"]').val("");
var loadUrl = "<?php echo base_url('show-people-data')?>";
$("#show_people").load(loadUrl);
}
});
return false;
});
My Controler我的控制器
public function add_people_data()
{
$id_people = $this->input->post('id_people');
$name_people = $this->input->post('name_people');
$phone_people = $this->input->post('phone_people');
$cekassignreviewer=$this->Model_reviewer->checkassignreviewer('data_people', $id_people, $name_people, $phone_people);
if ($cekassignreviewer > 0) {
$this->session->set_flashdata('failed',
"<script>swal({
title:'Failed!',
text: 'Number of people has been added',
icon: 'error',
confirmButtonText: 'Ok',
confirmButtonClass: 'btn btn-success'
});
</script>");
redirect(base_url('setting-reviewer'));
}else{
$data=$this->Model_reviewer->add_people();
echo json_encode($data);
}
My Model我的 Model
function add_people()
{
$data = array(
'id_people' => $this->input->post('uniid_reviewer'),
'name_people' => $this->input->post('name_people'),
'phone_people' => $this->input->post('phone_people'),
);
$result=$this->db->insert('data_people',$data);
return $result;
}
Thank you in advance先感谢您
IncomingRequest Class For CodeIgniter 4传入请求 Class 对于 CodeIgniter 4
If you are not within a controller, but still need access to the application's Request object, you can get a copy of it through the Services class:如果您不在 controller 内,但仍需要访问应用程序的请求 object,您可以通过服务 class 获取它的副本:
$request = \Config\Services::request();
With CodeIgniter's built in methods you can simply do this:使用 CodeIgniter 的内置方法,您可以简单地执行以下操作:
$something = $request->getVar('foo');
The getVar()
method will pull from $_REQUEST
, so will return any data from $_GET
, $_POST
, or $_COOKIE
. getVar()
方法将从$_REQUEST
拉取,因此将从$_GET
、 $_POST
或$_COOKIE
返回任何数据。 While this is convenient, you will often need to use a more specific method, like:虽然这很方便,但您通常需要使用更具体的方法,例如:
$request->getGet()
$request->getPost()
$request->getServer()
$request->getCookie()
In addition, there are a few utility methods for retrieving information from either $_GET
or $_POST
, while maintaining the ability to control the order you look for it:此外,还有一些实用方法可用于从
$_GET
或$_POST
检索信息,同时保持控制查找顺序的能力:
$request->getPostGet() - checks $_POST first, then $_GET
$request->getGetPost() - checks $_GET first, then $_POST
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.