0

i have a functions.php page with a dologout function

function doLogout() {
    if (isset($_SESSION['user_id'])) {
        unset($_SESSION['user_id']);
        unset($_SESSION['location']);
    }
    header('Location: index.php');
    exit;
}

and a home.php page with a logout button with onclick method to logout function which is as follow

function logout()
                            { 
                              $.ajax({
                              url: "functions.php",
                              type: "POST",
                              dataType: "dataString",
                              data: {func:"doLogout"},
                              }).done(function() {
                              alert( "LoggedOut Succesfully");
                               }); 
                                }
                              }
                       }

But this function is not working i tried looking at other answers but none of them actually answers how to call a function using ajax. Can anyone please help me? Thanks in advance

4
  • 1
    are you expecting that func:"doLogout" calls doLogout() by himself? Commented Sep 7, 2017 at 22:23
  • yes i searched for other answers online and one of it said to try it this way so i did but teven this isnt working Commented Sep 7, 2017 at 22:25
  • if i use a $_POST method in functions.php then it gives an error as that gets post only when logout button is been hit on the home screen in other cases it thorws an error saying $_post method variable is undefined Commented Sep 7, 2017 at 22:28
  • see stackoverflow.com/questions/4261133/… to handle that notice. Commented Sep 7, 2017 at 22:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.