• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

$ 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
系列文章
更多 icon
同类精品
更多 icon
继续加载