-
Notifications
You must be signed in to change notification settings - Fork 0
/
AjaxService.js
43 lines (40 loc) · 1.44 KB
/
AjaxService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
app.factory('ajaxService',function(){
return {
ajaxCall: function($scope,$http,$log,type,url){
$scope.loading = true;
if(type == "GET"){
$http({
method : type,
url : url
}).then(function sucessHandler(response) {
if(response.data.records == undefined)
$scope.myWelcome = response.data;
else
$scope.info = response.data.records;
}, function errorHandler(response) {
$scope.myWelcome = response.statusText;
})
.finally(function () {
// Hide loading spinner whether our call succeeded or failed.
$scope.loading = false;
});
}
else if(type == "POST"){
$http({
method : type,
url : url,
data : $scope.formdata,
headers : { 'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function sucessHandler(response) {
$scope.formdata = response.data;
}, function errorHandler(response) {
$scope.myWelcome = response.statusText;
})
.finally(function () {
// Hide loading spinner whether our call succeeded or failed.
$scope.loading = false;
});
}
}
};
});