angular 百度下拉 jsonp 请求

前端之家收集整理的这篇文章主要介绍了angular 百度下拉 jsonp 请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html>
<html>
	<head>
		<Meta charset="UTF-8">
		<title>百度下拉jsonp</title>
	</head>
	<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.js" type="text/javascript" charset="utf-8"></script>
	<body ng-app="dropBox">
		<div ng-controller="drop">
			<input type="text" ng-model="str"/>
			<ul>
				<li ng-repeat="lists in contentLists">{{lists}}</li>
			</ul>
		</div>
	</body>
	<script type="text/javascript">
		var app = angular.module( 'dropBox',[] );
		app.controller( 'drop',function ($scope,$http){
			$scope.str = "";
			$scope.contentLists = [];
			$scope.$watch( 'str',function(){
				$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{params : { 
					wd : $scope.str,cb : 'JSON_CALLBACK'
				}}).success(function(response){
					$scope.contentLists = response.s;
				}).error(function (){
					alert('操作失败!')
				});
			});
		});
	</script>
</html>
原文链接:https://www.f2er.com/angularjs/148682.html

猜你在找的Angularjs相关文章