Advertisement
handoyo

logout.js

Nov 12th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).on("click",'#button_logout',function(){
  2. try {
  3.         $.ajax({
  4.   url:"http://your_url/services/session/token",
  5.   type:"get",
  6.   dataType:"text",
  7.   error:function (jqXHR, textStatus, errorThrown) {
  8.    alert(jqXHR);
  9.    alert(textStatus);
  10.    // alert(errorThrown);
  11.   },
  12.   success: function (token) {
  13.         // Call system connect with session token.
  14.     $.ajax({
  15.  
  16.      url: "http://your_url/endpoint/user/logout.json",
  17.      type: 'post',
  18.      dataType: 'json',
  19.          beforeSend: function (request) {
  20.         request.setRequestHeader("X-CSRF-Token", token);
  21.       },
  22.      error: function (jqXHR, textStatus, errorThrown) {
  23.        alert('button_logout - failed to logout');
  24.        alert(JSON.stringify(jqXHR));
  25.        alert(JSON.stringify(textStatus));
  26.        alert(JSON.stringify(errorThrown));
  27.      },
  28.      success: function (data) {
  29.        alert("You have been logged out.");
  30.        $.mobile.changePage("index.html",{reloadPage:true},{allowSamePageTranstion:true},{transition:'none'});
  31.      }
  32.  });
  33.   }
  34. });
  35.  
  36. }
  37. catch (error) { alert("button_logout - " + error); }
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement