J
J
Jiakki-js2014-12-14 15:01:52
JavaScript
Jiakki-js, 2014-12-14 15:01:52

Get API with angularjs!?

Can't get json via angularjs
API https://api.privatbank.ua/api-info/exchangerate.html

var app = angular.module('spicyApp1', []);

app.controller('UserCtrl', ['$http', "$scope",
    function($http, $scope) {
      $http.jsonp("https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5").success(function(data) {
        console.log(data); 
      });
    } 
  ]);

The console outputs Resource interpreted as Script but transferred with MIME type text/html: " https://api.privatbank.ua/p24api/pubinfo?json&exch... "
Code plnkr.co/edit/W65fhjRHej56x4rcThpr?p=preview
Please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Terminaft, 2014-12-14
@Jiakki-js

The API gives incorrect headers - "text/html", but you need "text/javascript".
Using $http.get and $http.post won't work because the API doesn't return "Access-Control-Allow-Origin" headers.
Therefore, write a request to the API in php (or whatever you use there) with the return of the result immediately to the output, and pull it through $http.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question