저는 AngularJS로 시작했으며 매우 기본적인 예제를 시도했습니다. 웹 페이지에는 버튼이 있으며,이 버튼을 클릭하면 서버에서 json을 요청할 수 있습니다. 하지만 버튼을 클릭 할 때마다 코드가 오류 기능의 일부를 실행합니다.AngularJS로 JSON을 구문 분석 할 수 없습니다.
HTML 파일
<!DOCTYPE html>
<head>
<title> step 4</title>
</head>
<body ng-app="step4App">
<div ng-controller="FriendsCtrl">
<button ng-click="loadFriends()">Load Friends</button>
</div>
<script src="angular.min.js"></script>
<script src="xml2json.js"></script>
<script src = "step4.js"></script>
</body>
</html>
JS
var app = angular.module("step4App",[]);
app.controller("FriendsCtrl", function($scope,$http) {
$scope.loadFriends = function(){
$http({method:'GET',url:'http://localhost:8080/test.jsp', params:{name:"abc",no:"LBF1151638"}}).success(function(data) {
$scope.friends = data;
document.write('<p>two</p>');
document.write(data);
}).error(function() {
alert("error");
});
}
});
지금 JSON 응답을 반환 현재 JSP 페이지.
{"response":{"numFound":0,"start":0,"docs":[]}}
하지만 왜 항상 오류 기능을 실행하는지 이해할 수 없습니다.
브라우저 콘솔에서 요청이 작성되었으며 47 바이트 응답을 받았습니다 (JSON의 문자 수와 같음). 하지만 JSON이 인쇄되지는 않습니다.
감사합니다. 나는 방화범을 사용하여 노력했다. 상태는 200 (OK)이지만 angularJS는 404라고 말합니다. – krammer
JSP 파일의 논리를 확인하고 싶을 때가 있습니다. 또는 URL에 오타가 없는지 확인하십시오. –