将$ http响应发送回调用者html

时间:2015-03-09 18:00:16

标签: angularjs

我正在尝试实现一个简单的搜索功能,从search.html捕获搜索文本,进行HTTP调用以获取搜索结果并将其发送回search.html。我可以在控制台中从HTTP打印搜索文本和响应,但HTTP响应没有返回到search.html。这是我的代码:

angular.module('search' , [
]).controller("getRestulsCtrl", function ($scope,$http){

    $scope.submit = function() {
        if ($scope.text) {
            var qtext = $scope.text; // form value
            $http.defaults.headers.common['Authorization']  = 'Basic' + btoa('admin' + ':' + 'admin');
            $http.get("http://localhost:9002/search?keyword=xyz")
            .success(function (data) {
            $scope.searchResults = data
            console.log($scope.text);
            console.log(data)

        })
    }

} // form data

1 个答案:

答案 0 :(得分:-1)

James这里是来自HTML的代码提交表单:

<!DOCTYPE html>
<html ng-app ="search">
<head> <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Search Application</title>
</head>
<body ng-controller = "getRestulsCtrl">
<div>

<form ng-submit="submit()" ng-controller="getRestulsCtrl">
Enter Search : <input type="text" ng-model="text" name="searchText" />
<input type="submit" id="submit" value="Submit" />
</form>
<br>
<div ng-repeat = "results in $scope.searchResults.searchResults">
<br>
Doc Type : {{results.type}}
<br>
Trader: {{results.trader}} <br>
Buy/Sell : {{results.buysell}}<br>
Quantity : {{results.quantity}}<br>
Time : {{results.time}}<br>
</div>
<br> Facets: {{results.facets}}


    </div>
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular.min_1.js"></script>
</body>
</html>