Hello!

Tell me, please, how to adapt the live search plugin for ajax request / response?

http://jqueryui.com/autocomplete/#categories

In other words, how to send data to the server?

After sending, I plan to get this data in a .php file, process it, make a selection from the database and form a string like this:

{ label: "annhhx10", category: "Products" },

Then insert in var data = []

Or maybe you need to do something different?

Please help with the frontend to send data retrieval for this plugin! Thank!

  • and form a string like: - this is called JSON. In PHP, for example, see the code $ some = ['label' => 'annhhx10', 'category' => 'Products']; echo (json_encode ($ some)); die (); - Goncharov Alexander

1 answer 1

There are a few more examples in Russian. And as far as I can judge in the examples, almost your case. Good luck) Here is an example code for changing the source URL :)

 $( "#tags" ).autocomplete({ source: function(request, response){ // организуем кроссдоменный запрос $.ajax({ url: "http://ws.geonames.org/searchJSON", dataType: "jsonp", // параметры запроса, передаваемые на сервер (последний - подстрока для поиска): data:{ featureClass: "P", style: "full", maxRows: 12, name_startsWith: request.term }, // обработка успешного выполнения запроса success: function(data){ // приведем полученные данные к необходимому формату и передадим в предоставленную функцию response response($.map(data.geonames, function(item){ return{ label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName, value: item.name } })); } }); }, minLength: 2 });