Execute PHP code inside a jQuery condition

0

I have a modal window that when opened, shows the option to click on another button, which says yes or no.

If I click Yes, I intend to destroy the PHP session.

How can I do this within the jQuery code that opens the modal window?

JQUERY:

$(document).ready(function(){
     $('#modalLogout').click(function(){
          $('#yes').click(function(){
               // preciso de destruir a sessão <?php session_destroy(); ?>
          });
     });
});

I tried to use:

$(this).load("destroy.php");

And send to a PHP page but it did not work!

    
asked by anonymous 21.07.2015 / 03:10

1 answer

1

You can redirect to your destroy.php page that is probably destroying the session and making another redirect to the login screen.

$(document).ready(function(){
     $('#modalLogout').click(function(){
          $('#yes').click(function(){
              window.location = "destroy.php"

If you are going to use Ajax, you need to retrieve destroy.php need to return something to JavaScript to know the current status of the page and do whatever it takes, display a message or redirect the user somewhere.

    
21.07.2015 / 03:17