2
아래 코드가 상태가없는 오류 콜백을 실행하는 이유는 무엇입니까? Firefox의 웹 개발자는 상태 코드 200을보고합니다.
디버깅 할 방법이 있습니까?
<meta charset="utf8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script type="text/javascript">
function RoomListCtrl($scope, $http) {
$scope.getRooms = function() {
$http({method: 'GET', url: 'http://code.angularjs.org'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
alert('succes');
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
alert('error');
});
}
$scope.submit = function() {
this.getRooms();
}
}
</script>
<body ng-controller="RoomListCtrl"><form ng-submit="submit()">
<input type="text" value="" ng-model="search" name="search" >
</form></body>
실행중인 실제 코드입니까? 실제 요청이 차단되는 상태 (상태가 표시되지 않음) 인 [교차 도메인] (http://en.wikipedia.org/wiki/Same-origin_policy) 문제를 겪고있는 것 같습니다. – robertklep
예, 실제 코드입니다. Firefox에서이 코드를 로컬 파일로 실행하고 있습니다. 그게 문제가 될 수 있습니까? – koen
요청을 처리하는 원격 서버에 [CORS] (http : // enable-cors)가 없으면 일반적으로 도메인 간 AJAX 요청을 수행 할 수 없으므로 HTTP 서버를 통해 실행하더라도 오류가 발생합니다. org /)가 가능하지만,'code.angularjs.org'가 가지고있는 것처럼 보이지 않습니다. – robertklep