如何在angularjs中显示响应数据
how to show response data in angularjs
我有以下代码,但我的页面不显示数据…;(我不现在为什么请帮助我,我是新的angularjs。我正在调用web API其工作良好控制台日志显示json记录,但在我的页面记录现在显示…为什么
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:9000/employees").then(function (response) {
$scope.myData = response.data;
});
});
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<br>
<p>Today's welcome message is:</p>
<!--<h1>{{myWelcome}}</h1>-->
<ul>
<li ng-repeat="x in myData">
<li ng-repeat="x in myData">
{{ x.ProductName }} ',' {{ x.ProductDescription }}
</li>
<!--{{ x.ProductName + ', ' + x.ProductDescription }}-->
</li>
</ul>
</div>
</body>
</html>
result = [{"ID":1,"ProductName":"xcxc","ProductDescription":"xcxc","UnitPrice":2323,"QtyAvailable":23}]
chrome控制台日志
XMLHttpRequest无法加载http://localhost:9000/employees。没有"访问-控制-允许-起源"标头出现在请求上资源。因此,不允许访问原点'null'。
<li ng-repeat="x in myData">
{{ x.FirstName }} ',' {{ x.LastName }}
</li>
在你的代码中所有的东西都很好,可能angular没有加载或http没有响应正确:
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$scope.myData = [{
FirstName: "firts1",
LastName: "last1"
}, {
FirstName: "firts2",
LastName: "last2"
}, ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<br />
<!--// <p>Today's welcome message is:</p>-->
<!--<h1>{{myWelcome}}</h1>-->
<ul>
<li ng-repeat="x in myData">
{{ x.FirstName + ', ' + x.LastName }}
</li>
</ul>
</div>
</body>
</html>
<li ng-repeat="x in myData">
{{x.FirstName}}, {{x.LastName}}
</li>
我们必须使用JSONP来防止跨域策略。
var url = "http://localhost:9000/employees?callback=JSON_CALLBACK";
$http.jsonp(url)
.success(function(data){
console.log(data);
});
或
如果您想禁用策略,请遵循以下步骤
为Windows……在桌面上创建Chrome快捷方式。右环>属性>快捷方式编辑"目标"路径:
"C:'Program Files'Google'Chrome'Application'chrome.exe" --args --disable-web-security
然后尝试使用您现有的代码
相关文章:
- 将高图饼图中的文本居中显示为响应
- 显示IIS上javascript文件(SOAP请求)的XML响应
- Jqgrid-表未显示响应行为
- Servlet对浏览器上显示的纯文本Javascript的响应
- 在SPRING中从ajax调用响应时显示不可接受错误
- 尊重“; 〃;从HTML显示中的API响应返回的换行符(和特殊字符)
- 自动完成搜索无法正常工作,请不要迭代$中的所有元素.每个ul-li都会及时显示响应
- Jquery 自动完成插件未显示成功响应
- 如何从服务器响应中显示phonegap中的图像
- 在表中显示ajax响应不起作用
- 从javascript向Ashx处理程序发送xml数据,并在新窗口中显示响应
- JQuery Mobile+ChartJS:只在调整大小后显示响应条形图
- IE不会在新的弹出窗口中显示响应
- $http在angularjs应用中不显示响应
- 无法在ngDialog中显示响应数据
- 如何在angularjs中显示响应数据
- 在promise中将变量设置为Parse Query的result只显示响应中的第一项
- AJAX调用显示响应从php脚本在html
- 通过使用javascript发出HTTP GET请求来显示响应(xml)
- 如何使用$q.all(promises)并在网页上显示响应