Advertisement
valchak

JSON-request

Apr 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // makeRequest when data-Obj is transformed to string with JSON.stringify(data)
  2.     // We need to append: contentType: 'application/json'
  3.     function makeRequest(method, module, endpoint, auth) {
  4.         return {
  5.             url: BASE_URL + module + '/' + APP_KEY + '/' + endpoint,
  6.             method: method,
  7.             headers: {
  8.                 'Authorization': makeAuth(auth)
  9.             },
  10.             contentType: 'application/json'
  11.         }
  12.     }
  13.  
  14.     // post function when data-Obj is transformed to string with JSON.stringify(data)
  15.     function post(module, endpoint, auth, data) {
  16.         let obj = makeRequest('POST', module, endpoint, auth);
  17.  
  18.         if (data) {
  19.             obj.data = JSON.stringify(data);
  20.         }
  21.         return $.ajax(obj);
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement