dongmeiwei0226 2015-01-26 17:05
浏览 104

从AngularJS $ http请求中提取数据

I sending a request to my php file to get data from database from my AngularJS file. Some-time I am getting data also lot of time there is no response is coming. Here is my AngularJS code:

myApp.controller('PageCtrl', function PageCtrl($scope, $routeParams, $http) {
  $http.post(APP_URL + "server/FullDesc.php", {id: parseInt($routeParams.Id)}).success(function (data) {
    var timer = setTimeout(function () {
        $scope.Details = data[0];
        console.log(data);            
        $scope.$apply($scope.Details);
    }, 10);
  }, 'json');
})

In resposne I am getting output of my response like this

In image you can see there is no response showing. How to solve this issue.

  • 写回答

1条回答 默认 最新

  • duan2891 2015-01-26 18:39
    关注

    You should try adding an error scenario as well:

    myApp.controller('PageCtrl', function PageCtrl($scope, $routeParams, $http) {
    
        $http.post(APP_URL + "server/FullDesc.php", 
            {id: parseInt($routeParams.Id)}
        ).then(function(successResponse){
    
            var data = successResponse.data;
            console.log('successResponse', data);
            $scope.Details = data[0];
    
            //$scope.$apply($scope.Details); // assigning to scope should automatically do an apply
    
        }, function(errorResponse){
    
            console.log('errorResponse', errorResponse);
    
        });
    
    });
    

    Then you should also check what is being sent to the server and what the server sends back. It seems your server may be encountering an error and you are not sending an error response back.

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了