Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. window.onload = load;
  2.  
  3. let refresh_token = '';
  4.  
  5. function load() {
  6. $.ajax({
  7. method: 'POST',
  8. url: 'http://ignite.local/api/oauth/token',
  9. data: {
  10. username: 'admin@admin.com',
  11. password: 'secret',
  12. role: 1,
  13. },
  14. }).done(data => {
  15. refresh_token = data.refresh_token;
  16. getReport(data.access_token);
  17. });
  18. };
  19.  
  20. function getReport(token) {
  21. $.ajax({
  22. method: 'GET',
  23. url: '/api/projects/1/candidates/1/report',
  24. headers: {
  25. Authorization: `Bearer ${token}`,
  26. Accept: 'application/json',
  27. },
  28. })
  29. .done(html => {
  30. document.write(html);
  31. })
  32. .fail(xhr => {
  33. console.log(`${xhr.status}: ${xhr.responseText}`);
  34. console.log(`from server: ${xhr.responseJSON.message}`);
  35. });
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement