Advertisement
Guest User

context.js

a guest
Feb 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     static setAdminOption(option, value, handleSuccess, handleError) {
  2.         const formData = `option=${option}&value=${value}`;
  3.         // create an AJAX request
  4.         const xhr = new XMLHttpRequest();
  5.         xhr.open('post', __ROOT_PATH__ + 'api/adminS');
  6.         xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  7.         xhr.responseType = 'json';
  8.         xhr.addEventListener('save', () => {
  9.             if (xhr.status === 200) {
  10.                 handleSuccess(xhr.response.token);
  11.             } else {
  12.                 // failure
  13.  
  14.                 // change the component state
  15.                 const errors = xhr.response.errors ? xhr.response.errors : {};
  16.                 errors.summary = xhr.response.message;
  17.  
  18.                 handleError(errors);
  19.             }
  20.         });
  21.         xhr.send(formData);
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement