[英]Unable to receive ajax request in codeIgniter PHP
I have just started codeigniter and I am stuck at sending employee ID to my controller. 我刚刚启动codeigniter,但一直无法将员工ID发送给我的控制器。
Actually, I have a datatable which shows all the registered employees, and there is a button which get the ID of the employee of row clicked and send it to controller through ajax call but i am unable to receive it in my ajax call. 实际上,我有一个显示所有注册员工的数据表,并且有一个按钮可以单击该行的员工ID,并通过ajax调用将其发送给控制器,但是我无法在ajax调用中接收到它。
JS code JS代码
$('#viewAllEmployeeTable tbody').on('click', '.viewEmployeeDetail', function() {
var data = viewAllEmployeeTable.row($(this).parents('tr')).data();
console.log(data);
employeeID = data.employeeID;
alert(employeeID);
$.ajax({
url: "/ackamarackus/employee/viewEmployeeProfile",
type: "GET",
data: {
"employeeID": employeeID
},
dataType: "json",
success: function(data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
});
});
Controller 调节器
public function viewEmployeeProfile() {
$name = $this->input->post('employeeID');
echo "INPUT";
echo $name;
die();
}
This is what ajax is sending : employeeID:1000
这就是ajax发送的内容:
employeeID:1000
Can anyone tell me what I am doing here? 谁能告诉我我在这里做什么? I have already tried google and stack overflow link, but nothing solved my problem.
我已经尝试过谷歌和堆栈溢出链接,但没有解决我的问题。 Thanks
谢谢
您不能发送type: 'GET'
字段data
,将其更改为type:'POST'
,这将解决您的问题:)
You are sending employeeID as GET
method and accessing it as POST
in Your controller, change your type in ajax request to POST
as follows 您正在将EmployeeID作为
GET
方法发送并作为POST
在您的控制器中访问,将ajax请求中的类型更改为POST
,如下所示
$('#viewAllEmployeeTable tbody').on('click', '.viewEmployeeDetail', function() {
var data = viewAllEmployeeTable.row($(this).parents('tr')).data();
console.log(data);
employeeID = data.employeeID;
alert(employeeID);
$.ajax({
url: "/ackamarackus/employee/viewEmployeeProfile",
type: "POST", //Your problem here
data: {
"employeeID": employeeID
},
dataType: "json",
success: function(data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.