I'm trying to get a response from the Yandex-translate. Or the script does not work, or an incorrect request. And even it heder is not defended clear where the error heder is not defended . In the console: does not display anything, and even does not reach that place.
Online .

 var app = angular.module('jsbin', []); app.controller('DemoCtrl', function($scope, $http) { $scope.SendData = function() { // тут данные var textApi = 'Hello'; var langApi = 'en-ru'; var text1 = 'Hello'; var params = "key=" + keyAPI + "&text=" + textApi + "&lang=" + langApi; var url = "https://translate.yandex.net/api/v1.5/tr.json/translate"; var keyAPI = "trnsl.1.1.20130922T110455Z.4a9208e68c61a760.f819c1db302ba637c2bea1befa4db9f784e9fbb8"; var vm = this; $http({ url: url, method: 'POST', params: params }) .success(function(data, headers, status, config) { $scope.PostDataResponse = data; vm.data = data; console.log(data); }) .error(function(data, headers, status, config) { $scope.ResponseDetails = "Data: " + data + "<hr />status: " + status + "<hr />headers: " + header + "<hr />config: " + config; }) } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-resource.min.js"></script> <div ng-app="jsbin"> <div ng-controller="DemoCtrl as vm"> <button ng-click="SendData()">Send</button> <br>Data: {{PostDataResponse}} <br>{{vm.data}} {{vm.PostDataResponse}} Data: {{scope.PostDataResponse}} {{vm.data}} </div> </div> 

Closed due to the fact that off-topic participants Grundy , aleksandr barakin , user194374, Alex , Duck Learns to Hide 1 December '16 at 9:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Grundy, aleksandr barakin, Spirit of the community, Alex, Duck Learns to Hide
If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    Yes, indeed, parameters are objects. Thank. Here is a working version:

     var app = angular.module('jsbin', []); app.controller('DemoCtrl',function($scope, $http){ $scope.SendData = function () { // тут данные var textApi='Hello'; var langApi='en-ru'; var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?"; var keyAPI ="trnsl.1.1.20161125T152027Z.65e73e18a60f3051.7764a7a11754995544ad557501df9e14abbfb6e0"; var vm = this; $scope.method = 'POST'; $scope.url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?'; $http({ url: url, method:"POST", params:{key:keyAPI,text:textApi,lang:langApi}, }) .success(function(data,headers,status,config){ $scope.PostDataResponse = data; vm.data = data; console.log(data); }) .error(function(data,headers,status,config){ $scope.ResponseDetails = "Data: " + data + "<hr />status: " + status + "<hr />config: " + config; console.log("error1"); console.log(data); console.log(status); console.log(config) } ) } } ); 
     <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <meta charset="utf-8"> <title>Angular JS</title> </head> <body ng-app="jsbin"> <div ng-controller="DemoCtrl as vm"> <button ng-click="SendData()">Send</button> <br> Data: {{PostDataResponse}}<br> {{vm.data}} {{vm.PostDataResponse}} Data: {{scope.PostDataResponse}} {{vm.data}} </div> </body> </html> 

    • Please remember to mark your answer as a solution . In order to mark the answer accepted, click on the gray checkbox under the number to the left of the answer. Jackdaw will be green. This will mean that the answer is marked as a solution . - Alex

    And even it is not clear where the error heder is not defended.

    In fact, it is clear: the function with the parameters is passed to the error method

     function(data,headers,status,config){ 

    It is worth noting that the second parameter is headers

    In the body of the function, an attempt is made to access the header

     $scope.ResponseDetails = "Data: " + data + "<hr />status: " + status + "<hr />headers: " + header + // вот эта строка! "<hr />config: " + config; 

    As you can see, there really is no such variable.

    • For sure. But when you press the button, nothing happens. - Dmitry
    • @Dmitry, why not? There is a request for Yandex, it says that apiKey is bad, it sends status 403, you get into the error handler, you try to execute it and you fall when you try to get the value of an undeclared variable, and you get a message in the console about it. - Grundy
    • Really. But the trick is that the key was received and copied. Now got one more, the same thing. jsbin.com/sejupidabi/edit?html,js,console,output - Dmitry