Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从AngularJS$http请求中提取数据_Php_Angularjs_Response - Fatal编程技术网

Php 从AngularJS$http请求中提取数据

Php 从AngularJS$http请求中提取数据,php,angularjs,response,Php,Angularjs,Response,我向php文件发送一个请求,从AngularJS文件中获取数据库中的数据。有一段时间我得到的数据也很多时候没有回应。 以下是我的AngularJS代码: myApp.controller('PageCtrl', function PageCtrl($scope, $routeParams, $http) { $http.post(APP_URL + "server/FullDesc.php", {id: parseInt($routeParams.Id)}).success(function

我向php文件发送一个请求,从AngularJS文件中获取数据库中的数据。有一段时间我得到的数据也很多时候没有回应。 以下是我的AngularJS代码:

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');
})
作为回应,我得到了


在图像中,您可以看到并没有显示响应。如何解决此问题。

您还应尝试添加错误场景:

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);

    });

});

然后,您还应该检查发送到服务器的内容以及服务器返回的内容。您的服务器可能遇到错误,您没有发送错误响应。

为什么响应处理程序会在setTimeout中执行此操作$http.success()将等待响应。请检查请求以确保其正确发送。如果是,问题可能出在PHP代码中(它是否处理像“undefined”这样的id值)?尝试使用Postman(使用您传递的参数)测试api调用,以确保返回数据。您的PHP api调用可能抛出了一个错误。