Answer the question
In order to leave comments, you need to log in
Cordova, how to log in to another server?
Good day.
There was a task to write a mobile client, but there was a problem with authorization. Cross-domain request to do it turned out like this:
.service('$request', function($q, $http, $ionicPopup, $localStorage) {
return {
post: function(r, postData, urlParams) {
var defer = $q.defer(),
url = $localStorage.getObject('user').hostname + r + '?'
+ _.values(_.mapObject(urlParams || {}, function(v,k) { return k + '=' + v; })).join('&');
$http({
url: url,
method: "POST",
data: postData || {},
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
}
}).then(function(result) {
if (!result.data.success) {
$ionicPopup.alert({
title: 'Ошибка',
template: result.data.error
});
defer.resolve(false);
}
else {
defer.resolve(result.data);
}
});
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question