I make an https request to outer service in http://transltr.org/.
var reqUrl = "http://transltr.org/api/translate?text=dog&to=he";
var deferred = $q.defer();
$http.get(reqUrl).then(function(response) {
deferred.resolve(response);
alert("sada");
},function (error) {
deferred.reject(error);
});
return deferred.promise;
rrsponse is 200, and I get data:
but error alert fired. There is a way to get this data?
I also see error in console :
XMLHttpRequest cannot load http://transltr.org/api/translate?text=dog&to=he. The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'http://myDomain.co.il' is therefore not allowed access.
I also tried this version(in this case, no response at all):
var reqUrl = "http://transltr.org/api/translate";
var params = {
to: to,
text: text
};
var deferred = $q.defer();
var request = {
method: 'GET',
url: reqUrl,
dataType: "json",
contentType: "application/json; charset=utf-8",
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
'X-Requested-With': 'XMLHttpRequest',
'Access-Control-Allow-Origin': '*'
},
params: params
};
$http(request).success(function (data) {
deferred.resolve(data);
}).error(function (error) {
deferred.reject(error);
});