我是AngularJS中的JSON和$ http服务的新手。我试图从一个jsp文件(它在同一个文件夹中)得到响应。但是当我在服务器上运行它时,什么都不打印。也没有错误。
有人请帮忙。非常感谢您在这个问题上的时间和协助。
下面是我的html文件,其中我用AngularJS:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.js"> </script>
<script>
var myApp=angular.module("myApp",[]);
myApp.controller("myController",function($scope,$http){
$http.get("JSON.jsp").then(function(response){
$scope.array=response;
}).then(function(error){
console.log(error, 'can not get data.');
});
});
</script>
<meta charset="ISO-8859-1">
<title>AngularCheck</title>
</head>
<body ng-controller="myController" >
<div ng-repeat="arr in array">
{{arr.name}}
{{arr.age}}
</div>
</body>
</html>
下面是我的JSP文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSON page</title>
</head>
<body>
<%
out.println(" [{\"name\":\"jothi\",\"age\":\"20\"},{\"name\":\"Guru\",\"age\":\"22\"}]");
%>
</body>
</html>
要获得更有意义的回复,请将完整的错误消息发布为好。 –
@ jan.vdbergh“同样没有错误。” – jdgregson
@jdgregson首先,我使用了.then(function())。将它更改为.catch后没有错误。但仍然当我在服务器上运行它没有打印。 –