angularjs $http.get 总是拿不到结果

burrows9 2018-04-11 09:27:32
html:
<!doctype html>
<html lang="en-US">
<script src="angular.min.js"></script>
<script src="app.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl as ctrl">
<p>Usernmae : <input type="text" ng-model="name"></p>
<button ng-click="ctrl.retrieve();" name="button" type="button">Retrieve Price</button>
{{quotes}}
</div>
</body>
</html>
---
app.js
var app = angular.module('myApp', []);
app.config(['$httpProvider', function($httpProvider){
$httpProvider.defaults.timeout = 20000;
// $httpProvider.defaults.
}])
app.controller('myCtrl', function($scope, $http){
this.retrieve = function() {
alert($scope.name)
var req = {
method: 'GET',
url: 'http://www.baidu.com/'
}

$http(req).then(function(response){
alert('a');
}, function(response){
alert(response.status); //----> 每次的结果都是-1
alert('b');
});
};
});

新人使用Angularjs,请教下问题出在哪里。多些
...全文
300 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
burrows9 2018-04-12
  • 打赏
  • 举报
回复
引用 1 楼 functionsub 的回复:
跨域了啊,老铁。
你就是黑夜的那道⚡️啊,多谢多谢!
functionsub 2018-04-11
  • 打赏
  • 举报
回复
跨域了啊,老铁。

87,955

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧