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!

2 comments:

  1. Vineet Malhotra5 July 2012 at 12:40

    Very Usefull

    ReplyDelete

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from javascript and jquery training in chennai .
    or learn thru Javascript Training in Chennai.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. javascript and jquery training in chennai

    ReplyDelete