티스토리 뷰

spring memo

angular - ajax

고랑이. 2019. 11. 15. 14:39

ajax 선언

myApp.service('myService',['$http',function ($http){
	this.requestAjax = function(url, param, type, succ){
		$.ajax({
			method: type,
			url: url,
			data: param,
			async : false,
			crossDomain: true,
			beforeSend : function(xhr){
				xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
				xhr.setRequestHeader("Ajax", "true");
				
			},
			success:function(data, status){
				succ(data, status);
			},
			error:function(data, status, err){
				alert("error:"+ data.responseText);
			}
		})
	}
}])

 

호출

myApp.controller('rootCtrl',['$scope','$http','$compile','myService',function ($scope,$http,$compile,myService){

	$scope.search = function(data){
    	var param = {};
    	myService.requestAjax(url, param, 'POST', function(response){
			$scope.data = response;
		})
    }
}]);

 


 

ajax loading 처리

$(document).ready(function(){

	$(window)
    .ajaxStart(function(){
    	//ajax시작
    	loadingImg('show');
    })
	.ajaxStop(function(){
    	//ajax완료
    	loadingImg('hide');
    });
})

'spring memo' 카테고리의 다른 글

데이터베이스/스크립트에서 페이징하기(angular)  (0) 2019.11.15
web spinner  (0) 2019.11.15
[javascript] image resize  (0) 2019.10.24
input에 전화번호 하이픈(-)넣기  (1) 2019.10.24
nodejs 비동기 문제  (0) 2019.10.24
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함