无法在codeIgniter中接收到ajax请求PHP
问题描述:
我刚刚开始使用codeigniter,而且我坚持将员工ID发送给我的控制器。无法在codeIgniter中接收到ajax请求PHP
其实,我有一个数据表,显示所有注册的员工,并有一个按钮,获得单击的行的员工的ID并通过ajax调用发送给控制器,但我无法接收它在我的阿贾克斯呼叫。
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);
}
});
});
控制器
public function viewEmployeeProfile() {
$name = $this->input->post('employeeID');
echo "INPUT";
echo $name;
die();
}
这是AJAX是发送:employeeID:1000
谁能告诉我什么,我在这里做什么?我已经尝试谷歌和堆栈溢出链接,但没有解决我的问题。由于
答
你不能type: 'GET'
更改此发送场data
到type:'POST'
,这将解决您的问题:)
答
您发送雇员为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);
}
});
});
我的错误,我甚至没有费心去看看这个:/ –
@BilalZafar有时也与大家发生什么:) –