Advertisement
handoyo

login.js

Nov 11th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).on('click','#page_login_submit',function(){
  2. var name = $('#page_login_name').val();
  3.   if (!name) { alert('Please enter your user name.'); return false; }
  4.   var pass = $('#page_login_pass').val();
  5.   if (!pass) { alert('Please enter your password.'); return false; }
  6. try{
  7.     $.ajax({
  8.           url: "http://url/drupal/test/user/login.json",
  9.           type: 'post',
  10.           data: 'username=' + encodeURIComponent(name) + '&password=' + encodeURIComponent(pass),
  11.           dataType: 'json',
  12.           error: function(jqXHR, textStatus, errorThrown) {
  13.             alert('page_login_submit - failed to login');
  14.             alert(JSON.stringify(jqXHR));
  15.             alert(JSON.stringify(textStatus));
  16.             alert(JSON.stringify(errorThrown));
  17.           },
  18.           success: function (data) {
  19.           var drupal_user = data.user;
  20.           alert ('welcome ' + drupal_user.name);
  21.           $.mobile.changePage("index.html", "slideup");
  22.           }});
  23.  
  24.  
  25.       // END: drupal services user login
  26.       return false;
  27.   }
  28. catch(error) { alert("login - " + error)};
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement