我的 index.html 是:
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>HTTP Request</title>
<script src="angularjs"></script>
<script src="appjs"></script>
</head>
<body>
<div ng-controller="myCtrl">
Test here : <input ng-model="testString">
<p>Test String is : {{testString}}</p>
<button ng-click="search()">Send HTTP Request</button>
<p>Response:</p>
{{data}}
</div>
</body>
</html>
我的 app.js 是:
angular.module('myApp', [])
.controller('myCtrl', ['$scope', '$http', function($scope, $http) {
$scope.testString = "Hello....";
$scope.search = function() {
// alert("inside search");
$http.get('www.google.com', {},
function(response) {
$scope.data = response;
alert("success");
},
function(failure) {
alert("failure");
});
};
}]);
它正在根据警报(“内部搜索”)进入搜索()函数。但我既没有得到回应也没有失败。我应该在这里做什么?