I have this working now, but I had to use jQuery.ajax and not angular's
own. Here is what works:
SessionCreator.$inject = ['$http', '$q', '$rootScope', '$timeout', 'ENV',
'User'];
function SessionCreator($http, $q, $rootScope, $timeout, ENV, User) {
var deferred = $q.defer();
jQuery.ajax(ENV.apiEndPoint + '/user-init', {
accepts: 'application/json',
dataType: 'json',
headers: {
Accept: 'application/json',
Authorization: User.getAuth()
},
success: function(data) {
$rootScope.maintenance = false;
User.init(data.user);
$rootScope.totalReads = data.totalReads;
if (data.maintenance) {
$rootScope.maintenance = true;
$rootScope.maintenanceMsg = data.content;
}
deferred.resolve();
},
error: function(jqXHR, status, errorThrown) {
console.log('SessionCreator error jqXHR', jqXHR);
console.log('SessionCreator error status', status);
console.log('SessionCreator error errorThrown', errorThrown);
User.init(data.user);
$rootScope.totalReads = data.totalReads;
if (data.maintenance) {
$rootScope.maintenance = true;
$rootScope.maintenanceMsg = data.content;
}
jQuery('.loader-wrap').fadeOut();
$timeout(function() {});
}
});
return deferred.promise;
}
This does not work:
SessionCreator.$inject = ['$http', '$q', '$rootScope', '$timeout', 'ENV',
'User'];
function SessionCreator($http, $q, $rootScope, $timeout, ENV, User) {
var deferred = $q.defer();
// used text here to try and avoid preflight request. Didn't work.
$http
.get(ENV.apiEndPoint + '/user-init',
{
responseType: 'text',
headers: {
Accept: 'text/plain'
}
}
)
.success(function(data) {
$rootScope.maintenance = false;
User.init(data.user);
$rootScope.totalReads = data.totalReads;
if (data.maintenance) {
$rootScope.maintenance = true;
$rootScope.maintenanceMsg = data.content;
}
deferred.resolve();
})
.error(function(data, status, headers, config) {
console.log('SessionCreator error data', data);
console.log('SessionCreator error status', status);
console.log('SessionCreator error headers', headers);
console.log('SessionCreator error config', config);
User.init(data.user);
$rootScope.totalReads = data.totalReads;
if (data.maintenance) {
$rootScope.maintenance = true;
$rootScope.maintenanceMsg = data.content;
}
jQuery('.loader-wrap').fadeOut();
$timeout(function() {});
});
return deferred.promise;
}
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.