lundi 23 mars 2015

Send cookie with http request with Angular.$cookie or jQuery.cookie


Setting: ionic, cordova, angular.


So, I'm writing an Angular service that needs to send a cookie with the request to obtain an answer; i'm testing with Chrome --disable-web-security, so CORS shouldn't be an issue (in fact, until I disabled security, the XHTTP request did not complete at all).



angular.module('starter.services', [])
.factory('ActivityService', function () {
return {
'getActivity' : function ($scope) {
jQuery.cookie('cookie1', 1, {path: '/', domain: 'test.mysite.org'} );
jQuery.ajax('http://ift.tt/1CLc9gW',
{ data: {action: 'myaction', 'page': 1 },
method: 'POST',
success: function(data, textStatus, jqXFR) {console.log(data); console.log(textStatus)},
xhrFields: {withCredentials: true}
});

}
}
});


Problem is, I see the cookie in Chrome debugger after setting it and before the XHTTP request, but it's not sent. The server never receives it, and answers accordingly.


Please, don't chasten me for using jQuery with angular. I've tried angular $cookies, and was not able (??) to inject it properly; $cookieStore works (again ??) but it's too limited.


Thanks.





Aucun commentaire:

Enregistrer un commentaire