【发布时间】: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 ":""}
标签: php jquery angularjs codeigniter