A
A
Artem Anashev2014-11-13 21:25:59
PHP
Artem Anashev, 2014-11-13 21:25:59

Why does AngularJS $http.jsonp in Yandex Market API return an error even though the data has arrived?

The task is to load data from the Yandex Market API.
On AngularJS, using $http.jsonp I make a request for their resource, as a result, $promise returns an error (error), and it is displayed in the console
Uncaught SyntaxError: Unexpected token :
Although the network shows that there is data and it can be viewed, and 200 comes in the headers.
I make requests through the icsystem service.
Controller code

angular.module('YandexMarketApp')

    .controller('SettingsCtrl', function($scope, $http) {

        var url = 'http://market.icsystem.ru/v1/model/8454852.json?callback=JSON_CALLBACK';

            $scope.save = function() {
                $http.jsonp(url)
                    .success( function(data, status, headers) {
                        console.log('success');
                        console.log(data);
                    })
                    .error( function(data, status, headers) {
                        console.log('error');
                        console.log(data);
                    });
                };
            })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Levka9, 2014-11-20
@MadMed677

Because the format of the returned data is not pure json, but possibly wrapped in a string.
That is, to get json from what has come, you need to do this:
angular.fromJson(angular.fromJson(data));
jsonp is not able to do this (
yesterday I struggled with this by connecting ebay

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question