Tutorial :AJAX signout with Zend Framework and jQuery



Question:

When a logged user click the signout link I'd like to call the logout action without refresh the page or redirect. Any helps? Thanks!


Solution:1

You need to simply bind some code to your logout link/button that requests your logout action:

$("#logout").click(function() {      $.get("/foocontroller/logout", function() {          alert('Successfully logged out');      });      return false; // so the page does not refresh  });  

Returning false from the click event prevents the default 'link following' behaviour which would typically cause a refresh/redirect.


Solution:2

You can even do it in a more unobtrusive way:

$('a.logout').click(function () {      var logoutUrl = $(this).attr('href');      $.get(logoutUrl, function () {          alert('Logged out');      });      return false;  });  

What this does is it simply finds the logout link ($('a.logout')) and when you click the link will get "followed" in the back, without changing the page (the $(this).attr('href') part will get the url from the link). Replace alert('Logged out'); with what you want to happen after the user has been logged out.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »