我有site.com。每个请求都被重定向到这里(所以 'site.com/book'、'site.com/settings' ecc .. 指向 'site.com')然后我有site.com/api/其中 'site.com/api/ user', 'site.com/api/library/' ecc... 被重定向。
我正在尝试使用 AngularJS 的 $http 向site.com/api请求 JSON 对象。成功后,我收到状态 200,但响应是“site.com/index.html”的文本/html。
随请求发送的标头是: Accept: "application/json, text/plain, / " Content-Type: application/json;charset=utf-8
我尝试使用应用邮递员调试site.com/api/并且它按预期工作,因为我收到了正确的 JSON 对象。
我不知道这是否是某些 .htaccess 规则或 AngularJS 的 $routeProvider 的问题......(我在 'site.com' 中有一个 .htaccess 文件,在 'site.com/api' 中有另一个文件)。但我可能完全不在路上。也许有人可以帮忙?谢谢。
var config = {method: 'POST', url: 'site.com/api/', data: $scope.data};
$scope.login = function(){
$http(config)
.success(function(resp, status, headers, config){
console.log(resp);
})
.error(function(resp, status, headers, config){
console.log(status);
});
};