Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

login.js

By: handoyo on Nov 11th, 2013  |  syntax: JavaScript  |  size: 1.08 KB  |  views: 84  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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://your_url/endpoint/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. });