$http.get在响应中返回Html代码,而不是json对象
我试图使用angular$http.get方法从外部API获取一些数据,但我得到的是“html代码”,而不是“json对象”。当我尝试使用jQueryAjax调用API时,效果很好。这是密码$http.get在响应中返回Html代码,而不是json对象,json,angularjs,http-get,Json,Angularjs,Http Get,我试图使用angular$http.get方法从外部API获取一些数据,但我得到的是“html代码”,而不是“json对象”。当我尝试使用jQueryAjax调用API时,效果很好。这是密码 $http.get({ "url": 'https://ebaydemo.stamplayapp.com/api/cobject/v1/projects', "crossDomain": true, "headers": { "accept": "application/j
$http.get({
"url": 'https://ebaydemo.stamplayapp.com/api/cobject/v1/projects',
"crossDomain": true,
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"params": {
"populate": false,
"n": 10
},
"processData": false
}).success(function (response) {
console.log(response);// Response has 'html code'
});
编辑
下面是我现在得到的简短回应:
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-- >
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<base href="/">
<title></title>
我创建了一个小的HTML代码片段来调用您的代码,如下所示:
<html>
<body ng-app="app" ng-controller="eBayController">
<input type="button" value="EBay" ng-click="getFromEbay()"></input>
<script rc="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="ebay.js"></script>
</body>
})
我正在取回一个JSON对象。您的请求格式错误。这里有一个plunker,你可以看到它是如何工作的
看看
app.js
以及$http
是如何被使用的什么是html响应?内容类型不应该是“json”而不是“application/json”吗?请提供更多信息,否则我们帮不上忙…@EmirMarques嗨,因为响应很大,我正在粘贴一小段@IsmaelFuntes在编辑中添加了示例响应。请看一看,我在这方面有404个错误。得到404(好),这很奇怪。我不是。我收回了20个项目。是的,奇怪的是,它与jquery Ajax完美配合。您可能想尝试禁用您启用的任何浏览器插件。我有一个avast防病毒插件。禁用了它,但不起作用。我在这方面遇到了404错误。获取ebaydemo.stamplayapp.com/api/cobject/v1/projects 404(确定)您正在使用哪个浏览器?
/* global angular */
angular.module("app",[])
.controller('eBayController', function($scope,$http) {
$scope.getFromEbay = function() {
$http.get("https://ebaydemo.stamplayapp.com/api/cobject/v1/projects")
.success(function (response)
{
console.log(response);
});
}