【发布时间】:2014-06-24 07:42:05
【问题描述】:
我是 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);
});
};
}
【问题讨论】:
-
用浏览器http请求尝试example.com/anyservice上的get请求,看看服务是否真的响应
-
API 是否与加载 Angular 应用程序的域不同?在这种情况下,它可能是一个 CORS 问题。
-
我在 Rest Console 中检查过,服务响应正常。
标签: javascript json angularjs ionic-framework