$.ajax в autocomplete
Привет! Подскажите как осуществить $.ajax в autocomplete
$(input).autocomplete({ source: function(request, response) { $.ajax({ url: Drupal.settings.geo.path, dataType: 'json', data: { act: 'get_other_cities', country: $(selects['country']).val(), value: request.term, }, success: function(data) { <- вот тут не знаю как response({ return{ } }); <- и до сюда } }); }, autoFocus: true, }); Как осуществить success? |
Цитата:
|
:)
Я имел ввиду как вывести данные! |
Сделал так:
$(input).autocomplete({ source: function(request, response) { $.ajax({ url: Drupal.settings.geo.path, dataType: 'json', data: { act: 'get_other_cities', country: $(selects['country']).val(), value: request.term, }, success: function(data) { response($.map(data.cities, function(item) { var elementList = '<span class="city">' + item[1] + '</span>'; if (item[2] != '') { elementList += item[2] + ',<br>'; } if (item[3] != '') { elementList += item[3]; } return { label: elementList, value: item[1] } })); } }); }, autoFocus: true, }); Возвращается все, но html теги выводятся строкой (не обробатываются) |
Bezlepkin,
Используй .html() вместо .text() и будет счастье. Неплохо было бы показать функцию response, а так остается только гадать. |
А где вы увидели .text()?
А разьве это не функция response? response($.map(data.cities, function(item) { var elementList = '<span class="city">' + item[1] + '</span>'; if (item[2] != '') { elementList += item[2] + ',<br>'; } if (item[3] != '') { elementList += item[3]; } return { label: elementList, value: item[1] } })); |
Я еще видел такую фишку:
.data(и тут как то выводится html и все параметры для autocomplete) |
Сделал так, все работает.
А можно ли поменять классы для ul и li в выпадающем списке autocomplete? $(input).autocomplete({ source: function(request, response) { $.ajax({ url: Drupal.settings.geo.path, dataType: 'json', data: { act: 'get_other_cities', country: $(selects['country']).val(), value: request.term, }, success: function(data) { response($.map(data.cities, function(item) { return { cityID: item[0], label: item[1], value: item[1], city: item[1], state: item[2], district: item[3] } })); } }); }, autoFocus: true, }) .data('autocomplete')._renderItem = function( ul, item ) { return $( '<li onmousemove="Select.itemMouseMove(5, 17, this)" val="' + item.cityID + '"></li>' ) .data( "item.autocomplete", item ) .append('<a href=" + item.url + ">' + '<span class="city">' + item.city + '</span>' + item.state + "<br>" + item.district + "</a>") .appendTo( ul ); }; |
Часовой пояс GMT +3, время: 09:10. |