Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const http = (function () {
  2.  
  3.         const send = (url, method, body) => {
  4.  
  5.             const payload = {
  6.                 headers: {
  7.                     "Content-Type": "application/json",
  8.                 },
  9.                 method,
  10.                 body: JSON.stringify(body)
  11.             };
  12.  
  13.             return fetch(url, payload)
  14.                 .then(response =>{
  15.                 console.log(response.json());
  16.             response.json()
  17.         } );
  18.         };
  19.  
  20.         const post = (url, body) => send(url, 'POST', body);
  21.  
  22.         const get = (url) => send(url, 'GET', null);
  23.  
  24.         return {send, post, get};
  25.  
  26.     }());
  27.  
  28.     $("#logout").on('click', (ev) => {
  29.  
  30.     http.post("/users/logout")
  31.         .then(() => {window.location = '/users/login?logout'});
  32.  
  33.     ev.preventDefault();
  34.     return false;
  35.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement