×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Jun 6, 2017 9:46 AM
Modified: Jun 6, 2017 9:47 AM
Views: 1
Tags: no tags
  1. //Single service used for all ajax calls
  2. app.service("$ajax", function ($http, $rootScope, $q) {
  3.  
  4.    
  5.  
  6.     this.requestWithPromise_JSON = function (url, method, params) {
  7.  
  8.         return $http({
  9.             url: url,
  10.             method: method,
  11.             data: JSON.stringify(params),
  12.             headers: {
  13.                 "utoken": $rootScope.utoken,
  14.                 "Content-Type": 'application/json'
  15.             }
  16.         }).then(function (response) {
  17.  
  18.             return response.data;
  19.             // this callback will be called asynchronously
  20.             // when the response is available
  21.         }).catch(function (response) {
  22.  
  23.             //Catch error
  24.             return $q.reject(response.data);
  25.  
  26.         });
  27.         ;
  28.  
  29.     };
  30.  
  31. });
  32.