Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
AngularJS jsonp不为我工作_Angularjs - Fatal编程技术网

AngularJS jsonp不为我工作

AngularJS jsonp不为我工作,angularjs,Angularjs,我没有在html页面中获取数据。 home.html <!Doctype html> <html ng-app="myServiceApp"> <head> <title>Processing $http.jsonp() response in service</title> </head> <body> <div ng-controller="myServiceCt

我没有在html页面中获取数据。 home.html

<!Doctype html>

<html ng-app="myServiceApp">

<head>    
    <title>Processing $http.jsonp() response in service</title>        
</head>

<body>

<div ng-controller="myServiceCtrl">

    <h3>Processing $http.jsonp() response in service</h3>

    <button ng-click="doJSONPRequest()">Click and make JSONP request</button>    
    <p>Data Details: {{details}}</p>    
    <p>Status Code: {{statcode}}</p>    
</div>    
</body>
</html>

您的HTML页面中没有任何内容。因此,无论是angular还是您的脚本都不会被加载和执行


添加脚本,一切都会好起来。

直到包含angular.js文件,它就像普通的html页面一样。

使用下面的代码作为angular应用程序运行此页面。

<!DOCTYPE html>
<html>
<head>    
    <title>Processing $http.jsonp() response in service</title>        
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script>
    var app = angular.module('myServiceApp', []);
        app.controller('myServiceCtrl', function ($scope, $http) {

            $scope.doJSONPRequest = function () {

                var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK";

                $http.jsonp(url)

                    .success(function (data, status, headers, config) {

                        console.log(data)
                        $scope.details = data.found;
                        $scope.statcode = status;

                    }).error(function (data, status, headers, config) {

                        $scope.statcode = status;

                    });

            }

        });
    </script>

</head>

<body>
    <div ng-app="myServiceApp" ng-controller="myServiceCtrl">
        <button ng-click="doJSONPRequest()">Click and make JSONP request</button>    
        <p>Data Details: {{details}}</p>    
        <p>Status Code: {{statcode}}</p>    
    </div>    
</body></html>

正在处理服务中的$http.jsonp()响应
var app=angular.module('myServiceApp',[]);
app.controller('myServiceCtrl',函数($scope,$http){
$scope.doJSONPRequest=函数(){
变量url=”http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK";
$http.jsonp(url)
.success(函数(数据、状态、标题、配置){
console.log(数据)
$scope.details=data.found;
$scope.statcode=状态;
}).error(函数(数据、状态、标题、配置){
$scope.statcode=状态;
});
}
});
单击并发出JSONP请求
数据详细信息:{{Details}}

状态代码:{{statcode}}


您的HTML页面中没有任何
。因此,angular和您的脚本都不会被加载和执行。除此之外,您的代码工作正常:
<!DOCTYPE html>
<html>
<head>    
    <title>Processing $http.jsonp() response in service</title>        
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script>
    var app = angular.module('myServiceApp', []);
        app.controller('myServiceCtrl', function ($scope, $http) {

            $scope.doJSONPRequest = function () {

                var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK";

                $http.jsonp(url)

                    .success(function (data, status, headers, config) {

                        console.log(data)
                        $scope.details = data.found;
                        $scope.statcode = status;

                    }).error(function (data, status, headers, config) {

                        $scope.statcode = status;

                    });

            }

        });
    </script>

</head>

<body>
    <div ng-app="myServiceApp" ng-controller="myServiceCtrl">
        <button ng-click="doJSONPRequest()">Click and make JSONP request</button>    
        <p>Data Details: {{details}}</p>    
        <p>Status Code: {{statcode}}</p>    
    </div>    
</body></html>