Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <button type="submit">Log in</button>
  2.  
  3. var myButton = document.querySelector('button'); //I realize theres an easier jQuery for this
  4. var token;
  5.  
  6. function getToken(){
  7.  
  8. alert("get token");
  9. var settings = {
  10. "async": true,
  11. "crossDomain": true,
  12. "url": "...",
  13. "method": "POST",
  14. "headers": {
  15. "Content-Type": "application/json",
  16. "cache-control": "no-cache"
  17. },
  18. "processData": false,
  19. "data": "{ rn"Username":"username123",rn"Password":"password123"rn}"
  20. }
  21. alert("going to ajax");
  22. return $.ajax(settings);
  23. }
  24.  
  25. function handleData(data){
  26.  
  27. console.log(data);
  28. token = data.access_token;
  29. console.log(token);
  30. }
  31.  
  32. getToken().done(handleData);
  33.  
  34. myButton.onclick = function(e){
  35. e.preventDefault();
  36. getToken();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement