angularjs ajax $http 비동기 전송

북마크 추가

먼저 ajax 호출

$.ajax({

   

type: 'POST',

url: '/test',

data: data,

dataType : 'json', 

   success : function(response) {

      alert("성공");

   },error : function(response){

    alert("실패");

   }

}); 

 

angularjs에서도 구조는 비슷함

 

$http({

 

 method : 'POST',

 url : "/test",

 data : data,

 headers : {

         'Content-type' : 'application/json'

}

}).success(function(response) {

alert("성공:);

        }).error(function(response) {

alert("실패");

});

 

ajax 에서의 type은 method로 사용

 

구조는 아래와 같이 사용해야됨

 

<html ng-app="">

<div ng-controller="Ctrl">

~생략~

</div>

 

<script>

function Ctrl($scope, $http){

$http({

 ~생략~

});

}

</script>

 

 

 

AD
관리자
2014-07-20 11:33
SHARE