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

burrows9 burrows9 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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,请教下问题出在哪里。多些
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
burrows9
JavaScript 87,983 成员 224,681 内容