AntoLeNice Posted May 16, 2011 Share Posted May 16, 2011 Hi there, I am currently making a website where the background can be switched ( http://www.claudettefleuriste.com/new ). When we click on a colored square, the background changes. But the new session isn't set. Here's my code (php with a application/x-javascript header): SCRIPTS.PHP $(".orange").click(function(){ $("body").css("background-image", "url(images/bg2.jpg)"); $.ajax({ url : "js/session.php", type : "get", data : "couleur=orange", dataType : "html", success : function(){ alert("bg orange"); }, error : function(xhr,code){ alert(code); } }) }); <?php if(isset($_SESSION['bg'])) { if($_SESSION['bg'] == 'rose') { echo '$("body").css("background-image", "url(images/bg1.jpg)");'; } else if($_SESSION['bg'] == 'orange') { echo '$("body").css("background-image", "url(images/bg2.jpg)");'; echo 'alert("bg est orange")'; } else if($_SESSION['bg'] == 'mauve') { echo '$("body").css("background-image", "url(images/bg3.jpg)");'; } } else { echo '$("body").css("background-image", "url(images/bg1.jpg)");'; echo 'alert("no bg")'; }?> SESSION.PHP <?php if(isset($_GET['couleur'])) { $_SESSION['bg'] = $_GET['couleur']; } ?> My ajax script works (returns success), Firebug gives me: session.php?couleur=orange . I don't understand, session_start() is activated. Can anyone help me ? Thanks, Anto Link to comment https://forums.phpfreaks.com/topic/236564-jquery-ajax-and-php-sessions-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.