如何将数据 Codeigniter 控制器传递给 Angularjs 控制器
Posted
技术标签:
【中文标题】如何将数据 Codeigniter 控制器传递给 Angularjs 控制器【英文标题】:How to pass data Codeigniter Controller to Angularjs Controller 【发布时间】:2020-06-22 05:04:14 【问题描述】:试图将 Codeigniter 控制器响应传递给 angularjs CTRL 在 AngularJs 中:我做了 alert(response.data) 显示 Undefined data is notcoming data
Codeigniter 控制器代码:
function index()
// echo "inside function";
$data = validate_my_params(array('id' => 'required|id'));
if($data['status'] == 'success')
$result = $this->LowCredit_model->info($data['data']);
//print_r($result);
jsonSuccess($result,$result['succ_code']);
else
echo "error";
从模型中我可以得到打印数据如下:
Array
(
[status] => success
[id] => 7
[succ_code] => succ_update_1
[data] => Array
(
[id] => 7
[credit] => 0.00
[firstName] => Rahul
[lastName] => Joshi
[email] => rahul@gdiz.com
)
)
Angular js CTRL 代码:
$scope.init = function()
alert('init');
gdiztunnel.post(
'order/LowCredit',
id: $configId
).then(
function success (response)
response = response.data;
alert(response.data);
if(response.status == 'success')
alert('success1');
$scope.lowcreditCtrl.data = response.data;
alert($scope.lowcreditCtrl.data);
使 alert(response.data) 显示 Undefined
【问题讨论】:
使用console.log(response.data);检查结果删除警报(response.data);它会在 Browser-> Inspect Element->console check it 中显示结果 嗨 Boominathan Elango,我删除了我使用过的 console.log(response.data) 。显示相同的未定义。 响应数据不正确:function success (response) response = response.data;警报(response.data); 先检查响应函数是否成功(response) console.log(response); 嗨 Boominathan Elango,我检查了 console.log(response);这些值即将到来---- Array ( [status] => success [id] => 7 [succ_code] => succ_update_1 [data] => Array ( [id] => 7 [credit] => 0.00 [ firstName] => Rahul [lastName] => Joshi [email] => rahul@gdiz.com ) ) "status":"success","id":"7","succ_code":"succ_update_1","data ":"id":"7","credit":"0.00","firstName":"Rahul","lastName":"Joshi","email":"rahul@gdiz.com","elapsed_time ":"" 【参考方案1】:在你的控制器中隐藏 print_r($result); 然后检查控制台
function success(response)
console.log(response.data);
希望对你有帮助
【讨论】:
以上是关于如何将数据 Codeigniter 控制器传递给 Angularjs 控制器的主要内容,如果未能解决你的问题,请参考以下文章
将 codeigniter $data['foo'] 从控制器传递给视图
Codeigniter - 使用 json 将单个查询结果传递给控制器 - 如果存在