I have an html5 app which logs the user into drupal via services 3.11 but I am unable to connect.

Using the Chrome Postman plugin I can connect as expected. The difference between Postman and my code is that the cookie session is not being passed from my app. From what I have read the withCredential: true is supposed to pass the session cookie but it's not working for me?

  1. api/user/login.json - Logs the user in as expected
  2. api/user/token.json - returns the token as expected
  3. api/system/connect.json - Always returns the data for Anonymous user 0

The system/connect code sent after login and token is:

                    type: "POST",
                    url: connectUrl,
                    xhrFields: {
                        withCredentials: true
                    success: function (result) {
                    error: function (result) {
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader('X-CSRF-Token', Session.user_token);
  • I'm voting to close this question as off-topic because it is about code you wrote, for which you want to write better code, or you want to understand why it doesn't work, but you didn't show the code you are using, or the part of the code that is relevant for the question.
    – Mołot
    Commented Mar 1, 2015 at 18:28
  • Not sure I follow - The code shown is the code that is failing and yes, I would like to understand why it doesn't work. Just to clarify, I've been using the same snippet (taken from the jQuery examples) to do ajax posts with no problem. It was only after trying it with cross-origin that it started to fail. After researching extensively I'd learned that 'withCredentials: true' is supposed to pass the session cookie, but for some reason it's not doing it. Commented Mar 2, 2015 at 20:57

1 Answer 1


For anyone else who stumbles across this problem I did finally manage to solve it with the following which ensures the credentials are pass for each call consistently. I'm assuming where CORS adds in the additional OPTIONS request, the credentials we're going through.

jQuery.support.cors = true;
        xhrFields: {
            withCredentials: true   // Pass session cookie with requests

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.