From 930934f4d22ce4397bcc85cde33c32acef2ec622 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 1 Sep 2016 15:55:25 -0400 Subject: [PATCH] Autocomplete: Change JSONP demo to use local data source Fixes #14974 --- demos/autocomplete/remote-jsonp.html | 23 ++++++++++------------- demos/autocomplete/search.php | 13 +++++++++---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/demos/autocomplete/remote-jsonp.html b/demos/autocomplete/remote-jsonp.html index d43dbbb75..45976bb2c 100644 --- a/demos/autocomplete/remote-jsonp.html +++ b/demos/autocomplete/remote-jsonp.html @@ -10,7 +10,6 @@ .ui-autocomplete-loading { background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat; } - #city { width: 25em; } @@ -44,9 +41,8 @@
- - - Powered by geobytes.com + +
@@ -55,7 +51,8 @@
-

The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are cities, displayed when at least three characters are entered into the field. The datasource is the geobytes.com webservice. That data is also available in callbacks, as illustrated by the Result area below the input.

+

The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.

+

The datasource is a server-side script which returns JSONP data, specified via a function which uses jQuery.ajax() for the source option.

diff --git a/demos/autocomplete/search.php b/demos/autocomplete/search.php index 04bda4224..489b30c1e 100644 --- a/demos/autocomplete/search.php +++ b/demos/autocomplete/search.php @@ -1,6 +1,6 @@ "Larus heuglini" ); - $result = array(); foreach ($items as $key=>$value) { if (strpos(strtolower($key), $q) !== false) { @@ -584,6 +583,12 @@ foreach ($items as $key=>$value) { } // json_encode is available in PHP 5.2 and above, or you can install a PECL module in earlier versions -echo json_encode($result); +$output = json_encode($result); + +if ($_GET["callback"]) { + $output = $_GET["callback"] . "($output);"; +} + +echo $output; -?> \ No newline at end of file +?> -- 2.39.5