Advertisement
Guest User

dashboard.js

a guest
Nov 6th, 2013
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var nid;
  2. $('#page_dashboard').on('pageshow',function(){
  3. try{
  4. $.ajax({
  5.   url:"http://10.0.2.2:81/drupal/services/session/token",
  6.   type:"get",
  7.   dataType:"text",
  8.   error:function (jqXHR, textStatus, errorThrown) {
  9.    // alert(errorThrown);
  10.   },
  11.   success: function (token) {
  12.     // Call system connect with session token.
  13.     $.ajax({
  14.       url: 'http://localhost:81/drupal/test/system/connect.json',
  15.       type: "post",
  16.       dataType: "json",
  17.       beforeSend: function (request) {
  18.         request.setRequestHeader("X-CSRF-Token", token);
  19.       },
  20.       error: function (jqXHR, textStatus, errorThrown) {
  21.       //  alert(errorThrown);
  22.       },
  23.       success: function (data) {
  24.         alert('Hello user ' + data.user.name);
  25.       }
  26.     });
  27.   }
  28. });
  29. }
  30. catch(error) { alert("page_dashboard - " + error)};
  31. });
  32. $(document).on("click",'#button_logout',function(){
  33. try {
  34.  $.ajax({
  35.      url: "http://10.0.2.2:81/drupal/test/user/logout.json",
  36.      type: 'post',
  37.      dataType: 'json',
  38.      error: function (XMLHttpRequest, textStatus, errorThrown) {
  39.        alert('button_logout - failed to logout');
  40.        console.log(JSON.stringify(XMLHttpRequest));
  41.        console.log(JSON.stringify(textStatus));
  42.        console.log(JSON.stringify(errorThrown));
  43.      },
  44.      success: function (data) {
  45.        alert("You have been logged out.");
  46.        $.mobile.changePage("index.html",{reloadPage:true},{allowSamePageTranstion:true},{transition:'none'});
  47.      }
  48.  });
  49. }
  50. catch (error) { alert("button_logout - " + error); }
  51. return false;
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement