0

I have this javascript to update a php session variable :

  $(document).ready(function(){
        $('#facebook_img').live('click',function(){
login_condetion = 1;                
$.ajax({
                type: "POST",
                url: 'facebook_login_condition_variable.php',
                data:{login_condetion:login_condetion},
                dataType: "json",
                success: function(data)
                {
                    alert(123);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    /*alert(XMLHttpRequest);
                    alert(textStatus);
                    alert(errorThrown);
                    alert(XMLHttpRequest.responseText);*/
                }
            });
        });
    });

I print the session value before and after this code but it never change and when I alert responsText I get nothing and XMLHttpRequest gives me object object error .

This is my php code :

<?php 
$temp = $_POST['login_condetion'];
if(!empty($temp) && $temp != 0)
{
   $_SESSION['do_not_allow_auto_facebook_login'] = 1;
}
else    
{
    $_SESSION['do_not_allow_auto_facebook_login'] = 0;
}
$go = $_SESSION;
echo json_encode($go);
?>

Is there any problem with dataType of ajax function ? or it is a php session problem ? Please help me because I have been stuck here for long time.

4
  • .live() still using it, .on() is recommended. Commented Jun 3, 2014 at 11:28
  • 1
    Not sure if this matters, but "condition" is correctly spelled in some code and in other code, misspelled "condetion" Commented Jun 3, 2014 at 11:28
  • 2
    Are you calling session_start() in the top of your PHP file? Commented Jun 3, 2014 at 11:30
  • object object Is not an error Commented Jun 3, 2014 at 11:57

2 Answers 2

2

Some suggestions..

  1. Do you start the session at top of the page where you use it.

    session_start();

  2. in php code replace

    $go = $_SESSION;

with

 $go = $_SESSION['do_not_allow_auto_facebook_login'];

3.Do you need the datatype json, if not remove this line

echo json_encode($go);

and use

echo $go;
Sign up to request clarification or add additional context in comments.

Comments

2

Use session_start() at the top of your script:

<?php
session_start();
...

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.