До того, как я добавил dataType: "jsonp"
, мое автозаполнение работало. Теперь мне нужно сделать его совместимым с несколькими доменами, используя, таким образом, jsonp
Я добавил dataType: "jsonp"
и ?callback=
в конце URL.
Но я все еще получаю это сообщение об ошибке:
Notice: Undefined index: callback in /var/www/storelocator/wp-content/themes/storelocator/classes/jquery.class.php on line 101
В строке 101 у меня есть следующий код:
echo $_GET['callback'] . '('.json_encode($data).')';
Мой JavaScript выглядит так:
jQuery('.autocomplete_brand').autocomplete({
source: siteURL +"/wp-content/themes/storelocator/include/jquery.php?instance=search_brand&limit=25?callback=",
dataType: "jsonp",
minLength: 2,
search: function(event, ui) { jQuery(this).toggleClass( "autocomplete_loading" ); },
open: function(event, ui) { jQuery(this).toggleClass( "autocomplete_loading" ); },
select: function(event, ui) { jQuery('#ID').val(ui.item.id); }
}).data( "autocomplete" )._renderItem = function( ul, item ) {
return jQuery( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>"+ item.value + "</a>" )
.appendTo( ul );
jQuery(this).toggleClass( "autocomplete_loading" );
}