{"id":6943,"date":"2014-05-12T00:42:26","date_gmt":"2014-05-12T00:42:26","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/12\/uncaught-syntaxerror-unexpected-token-when-calling-angularjs-http-jsonp-collection-of-common-programming-errors-2\/"},"modified":"2014-05-12T00:42:26","modified_gmt":"2014-05-12T00:42:26","slug":"uncaught-syntaxerror-unexpected-token-when-calling-angularjs-http-jsonp-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/12\/uncaught-syntaxerror-unexpected-token-when-calling-angularjs-http-jsonp-collection-of-common-programming-errors-2\/","title":{"rendered":"Uncaught SyntaxError: Unexpected token &lt;, when calling angularJS $http.jsonp-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to work with the IUCN Red List web services API (here&#8217;s an example output). Unfortunately I haven&#8217;t been able to find any documentation other than this one-off Gist. It looks as though the API is constructing an HTML document rather than returning a data object, which isn&#8217;t something I&#8217;ve experienced in the past. I also notice that in the example there is no mention of a <code>?callback=JSON_CALLBACK<\/code> in the URL, which I would expect when dealing with JSONP.<\/p>\n<p>I&#8217;ve constructed an http request in AngularJS like so:<\/p>\n<pre><code>atRiskApp.controller('IucnController', ['$scope', '$routeParams', '$http', function ($scope, $routeParams, $http) {\n  $scope.iucn = $routeParams.iucn; \/\/ pulling a number from the URL: ex. 22718591\n\n  $scope.getIUCN = function () {\n    var iucnUrl = 'http:\/\/api.iucnredlist.org\/details\/' + $scope.iucn + '\/0.js';\n\n    $http.jsonp( url )\n      .success( function (response) {\n        console.log(response);\n      })\n      .error( function (response) {\n        console.log(response);\n      });\n  };\n}]);\n<\/code><\/pre>\n<p>Although the HTML document is being successfully passed to my app I&#8217;m getting the following error message: <code>Uncaught SyntaxError: Unexpected token<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to work with the IUCN Red List web services API (here&#8217;s an example output). Unfortunately I haven&#8217;t been able to find any documentation other than this one-off Gist. It looks as though the API is constructing an HTML document rather than returning a data object, which isn&#8217;t something I&#8217;ve experienced in the past. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6943","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6943"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6943\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}