Friday, 25 June 2010

How to check session is exit or not using ajax call with jquery?

Hey fox please do the below mentioned code to check it out whether session is exist or not via ajax call:


Write down the following code while call ajax;

function callAjax()
    {
        $.ajax({       
               data: { fname: 'ashwani kumar' },             
              type: 'POST',
                  url: 'ajax.php',
                success: function(data) {
                    alert('success');
                    $('#content').html(data);           
                 },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                     //alert(XMLHttpRequest.status);
                    if (XMLHttpRequest.status === 500) {
                      location.href = 'index.php';
                    }
                  }
            });
    }

IN ajax.php file on top of the page write down the following code in your script:

if(!isset($_SESSION['name']))
{
    header("HTTP/1.0 500 Not Found");
    exit;
}


Cheers!

1 comment: