Come with jsonp, implement cross-domain, and then implement the drop-down list of the search box. Use Baidu and 360 to try it out respectively.
Baidu:After the url is intercepted, the red part needs to be replaced:/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=Data&cb=JSON_CALLBACK
360:./suggest?callback=JSON_CALLBACK&word=Data
Notice:Need to run in a server environment
Ideas:
1. Declare angular
2. The $http service is called in the controller function to read the data on the web server.
3.Binding data $=[] is used to store the returned data
4. The binding function $=function(){} is executed when keyup
5. Call $(url)
6. Return the result and assign it to $, $=;
The following code
<!doctype html> <html ng-app="app"> <head> <meta charset="utf-8"> <style> </style> <script src=""></script> <script> var app=('app',[]); //statement('test',function ($scope,$http){ // $http is a service for reading data on a web server. $=[]; // Bind data $=function (){ // $(url) is a function used to read server data. $('/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd='+$scope.t1+'&cb=JSON_CALLBACK').success(function (data){ //The returned result is assigned to $ $=; }); }; }); </script> </head> <body ng-controller="test"> <div> <!-- The input content is bound tot1 ,ng-keyup="show()" --> <input type="text" ng-model="t1" ng-keyup="show()" /> </div> <ul> <!-- Data display --> <li ng-repeat="item in data">{{item}}</li> </ul> </body> </html>
The above is the Angular implementation cross-domain (drop-down list of the search box) introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!