Advertisement
fahmihilmansyah

jspuyeng

Jun 22nd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ================function menggunakan javascript ajax==========
  2. function loadDoc() {
  3.   var user = document.getElementById('name').value;
  4.   var password = document.getElementById('password').value;
  5.   var xhttp = new XMLHttpRequest();
  6.   xhttp.onreadystatechange = function() {
  7.     if (xhttp.readyState == 4 && xhttp.status == 200) {
  8.       document.getElementById("demo").innerHTML = xhttp.responseText;
  9.     }
  10.   };
  11.   xhttp.open("POST", "http://123.123.123.20:8080/SecurityApi/system/login", true);
  12.   xhttp.send(btoa(user + ":" + password));
  13. }
  14.  
  15. ================function menggunakan jquery ajax =============
  16. var name = $("#name").val();
  17.       var password = $("#password").val();
  18.       var strings= JSON.stringify(btoa(name +":"+password));
  19. $.ajax({
  20. url:"http://123.123.123.20:8080/SecurityApi/system/login",
  21.       dataType: 'json',
  22.       type: 'post',
  23.       contentTYpe: "application/json",
  24.       data: strings,
  25.       processData: false,
  26.       success: function( data, textStatus, jQxhr ){
  27.           alert(data);
  28.       },
  29.       error: function( jqXhr, textStatus, errorThrown ){
  30.           console.log( errorThrown );
  31.       }
  32.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement