标签:cti var 百度 timer cli utf-8 搜索功能 hang jsonp
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>百度搜索</title>
<script src="js/angular.min.js"></script>
<script>
var m1=angular.module(‘myApp‘,[])
m1.controller(‘myCtrl‘,[‘$scope‘,‘$timeout‘,‘$http‘,function($scope,$timeout,$http){
$scope.search=function(str){
$timeout.cancel(timer)
var timer=$timeout(function(){
$http({
method:‘JSONP‘,
url:‘https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=‘+str+‘&cb=JSON_CALLBACK‘,
}).success(function(data){
console.log(data)
$scope.dataList=data.s
})
},200)
}
}])
</script>
</head>
<body>
<div ng-controller="myCtrl">
<input type="text" ng-model="searchVal" ng-change="search(searchVal)">
<input type="button" ng-click="search(searchVal)" value="搜索">
<ul>
<li ng-repeat="data in dataList">{{data}}</li>
</ul>
</div>
</body>
</html>
标签:cti var 百度 timer cli utf-8 搜索功能 hang jsonp
原文地址:http://www.cnblogs.com/zy88zj91/p/7153050.html