php - Method result is null when using ajax call yii2 -


here controller:

public function actionusagereport($from = 0, $to = 10)     {         $service = new service;         $ibs_username = yii::$app->user->identity->services[0]->ibs_username;          $results = $service->fetchuserconnections($ibs_username, $from, $to);         foreach ($results $index => $result) {             $usages[$index]['login_time_formatted'] = $result['login_time_formatted'];             $usages[$index]['logout_time_formatted'] = $result['logout_time_formatted'];             $usages[$index]['duration_seconds'] = $result['duration_seconds'];             $usages[$index]['bytes_in'] = $result['bytes_in'];             $usages[$index]['bytes_out'] = $result['bytes_out'];             $usages[$index]['credit_used'] = $result['credit_used'];             $usages[$index]['remote_ip'] = $result['remote_ip'];         }          if (yii::$app->request->isajax) {              yii::$app->response->format = \yii\web\response::format_json;              return $usages;         } else {             return $this->render('usagereport', ['usages' => $usages]);         }     } 

when open page action normally, method executes fine , returns values in array make own array foreach , data fine,but when send ajax request view, result of method executions null ($results variable) following error in console:

invalid argument supplied foreach() 

my ajax request hasn't got problems , works fine when debug manually console , check variables. , here js code:

$.ajax({             url: '/crm/usage-report',             type: 'get',             datatype: 'json',             data: { from:0, to:10 },             error: function(xhr, status, error) {              console.log(xhr.responsetext);             },             success: function(data) {                 console.log(data);         }}); 

why works fine in normal page loading method not working through ajax call?


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -