Symfony, jQuery.ajax () call, session loss

I am writing a web application using Symfony 1.3. I have a problem with losing my sessions after I invoke an action through a jQuery call $.ajax(). Everything happens in the following order:

  • The action sets the session variable as follows:

    $this->getUser()->setAttribute('uploaded-files', $uploadedFiles);
    
  • Then, when the action invokes the view component, the resulting HTML page contains the following call:

    $.ajax({
      type: "POST",
      url: '<?php echo url_for("content/merge"); ?>',
      cache: false,
      success: mergingCompleteCallback
    });
    
  • I press a button that launches the above ajax call. The call performs the appropriate action method, but when I print the contents of the uploaded-files session variable, it is empty.

    I also checked if the session identifier remains between the call to the page that sets the variable and the page that reads the variable (ajax call), and the session ID has not changed. I searched the watch online and I could not find a solution.

+5
source share
2 answers

I had a similar problem and the problem was that I used the host value to store cookies with "www", that is www.mydomain.com, and I made an Ajax request without www '

The solution uses a wildcard pattern, such as a host. Like .mydomain.com , since your host stores the session cookie at the end of the browser.

Just make sure you're not a victim of this?

+3

, AJAX. , .

dev? , , .

+1

All Articles