$ http.get返回Html代码作为响应而不是json对象
it1352
帮助1人
问题说明
我正在尝试使用angular $ http.get方法从外部API获取一些数据,但是作为响应,我正在获取"html代码"而不是"json对象".当我尝试使用jquery ajax调用API时,它工作正常.这是代码
I'm trying to get some data from an external API using angular $http.get method , but i'm getting 'html code' instead of 'json object' in response. When i tried calling the API using jquery ajax it worked fine. Here's the code
$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'
});
修改 这是我现在得到的简短回复:
Edit Here's the short snippet of response i'm getting now:
<!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="https://www.it1352.com/">
<title></title>
正确答案
#1
我创建了一些HTML代码段来调用您的代码,如下所示:
I created a little HTML snippet to call your code like below:
<html>
<body ng-app="app" ng-controller="eBayController">
<input type="button" value="EBay" ng-click="getFromEbay()"></input>
<script rc="https://ajax.谷歌apis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://www.it1352.com/ebay.js"></script>
</body>
,然后将JavaScript简化为:
and then just reduced the JavaScript to this:
/* 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);
});
}
})
然后我得到一个JSON对象.
and I'm getting a JSON object back.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgkefb
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20