Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Javascript Angularjs-调用json web服务总是返回404_Javascript_Json_Angularjs_Ionic Framework - Fatal编程技术网

Javascript Angularjs-调用json web服务总是返回404

Javascript Angularjs-调用json web服务总是返回404,javascript,json,angularjs,ionic-framework,Javascript,Json,Angularjs,Ionic Framework,我对angularjs是新手。我用的是离子框架。我试图调用json web服务,但它总是返回404 当我在浏览器中尝试时,它工作得非常好 这是我的密码: function FetchCtrl($scope, $http) { $scope.fetch = function() { $http({method: 'GET', url: 'http://example.com/anyservice'}). success(function(data,

我对angularjs是新手。我用的是离子框架。我试图调用json web服务,但它总是返回404

当我在浏览器中尝试时,它工作得非常好

这是我的密码:

function FetchCtrl($scope, $http) {

    $scope.fetch = function() {

        $http({method: 'GET', url: 'http://example.com/anyservice'}).
          success(function(data, status, headers, config) {

            alert("data "+data);
          }).
          error(function(data, status, headers, config) {

            alert("error "+status);

          });

      };
 }

使用Chrome或FireFox开发者工具,打开网络选项卡,然后试一试,看看实际发生的请求是什么,这将有助于您找到问题。

尝试使用浏览器http请求执行get请求,查看服务是否真的响应了加载angular应用程序以外的其他域上的API?在这种情况下,这可能是CORS问题。我在Rest控制台中进行了检查,服务响应正常。嘿,我在Chrome Developer工具上再次进行了检查,并指出我的服务器不允许从其他服务器访问服务。因此,我创建了一个服务并将其放置到我的服务器上。现在我得到了正确的回答。谢谢你的帮助。