log*_*yer 6 javascript get angularjs spring-4
我有一个非常简单的Spring Rest后端,它返回JSON数据.宁静的URL在我的浏览器中工作如下:
http://localhost:8080/abc/runlist
它返回如下数据:
[{"stock_num":"KOH19","damage":"Toronto (Oshawa)"},{"stock_num":"AZ235","damage":"Toronto (Oshawa)"},...
我有一个独立的html页面,不属于我的网络应用程序.我只想测试我的角度代码是否获取数据然后循环遍历它.
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in names">
{{ x }}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:8080/abc/runlist")
.success(function (response) {$scope.names = response.records;});
});
</script>
yo yo
</body>
Run Code Online (Sandbox Code Playgroud)
`
为什么不起作用?我在Spring遇到了一些需要实现CORS的东西.我这样做了但仍然没有回复:
@Component
public class SimpleCORSFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse res, FilterChain
chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS,
DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
chain.doFilter(req, res);
}
public void init(FilterConfig filterConfig) {}
public void destroy() {}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10972 次 |
| 最近记录: |