1

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="/">
<title></title>
9
  • 1
    Whats html response? Commented Oct 6, 2015 at 12:19
  • 1
    Shouldn't content-type be 'json' and not 'application/json'? Commented Oct 6, 2015 at 12:23
  • More information please, in other case we cant help... Commented Oct 6, 2015 at 12:23
  • @EmirMarques Hi, as the response is big, i'm pasting a short snippet of it. <!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> Commented Oct 6, 2015 at 12:25
  • @IsmaelFuentes Added sample response in the edit. Please have a look Commented Oct 6, 2015 at 12:29

2 Answers 2

2

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.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="ebay.js"></script>
</body>

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);
        }); 
   }

})

and I'm getting a JSON object back.

Sign up to request clarification or add additional context in comments.

10 Comments

I'm getting 404 error on this. GET ebaydemo.stamplayapp.com/api/cobject/v1/projects 404 (OK)
That's very odd. I'm not. I get 20 items back.
Yeah, its strange that it works perfectly with jquery ajax
You may want to try disabling any browser plug-ins you have enabled.
I have one avast antivirus plugin. Disabled it, but didn't work
|
0

Your request is in a wrong format. Here is a plunker where you can see how it works.

http://plnkr.co/edit/QFCs8kiPvcErmeRePBMd

Take a look at app.js and how the $http is being used

2 Comments

I'm getting 404 error on this. GET ebaydemo.stamplayapp.com/api/cobject/v1/projects 404 (OK)
Which browser are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.