javascript - Why is my autocomplete function not working? -
i've got jquery autocomplete function working fine untill rewrite source function.
the odd part both functions returning exact same data, however, when add together ajax function source, autocomplete function no longer works.
working code:
$('#q').autocomplete({ source:'getklanten.php' }).data( "ui-autocomplete" )._renderitem = function( ul, item ) { homecoming $( "<li>" ) .append( "<a>" + item.naam + "</a>" ) .appendto( ul ); };
this code returns in console
get http://myurl/getklanten.php?term=comp [{"naam":"company name","id":12345}]
and autocomplete function works intended , returns result.
not working code variable function:
var dynamicvar = $('#zxc').prop('checked'); $('#zxc').change(function(){ dynamicvar = $('#zxc').prop('checked'); dynamicvar = $('#zxc').is(':checked'); console.log(dynamicvar); }); $('#q').autocomplete({ //source:'getklanten.php' source: function(request, response) { $.ajax({ url: "getklanten.php", data: { term : request.term, supplier : $('#zxc').is(':checked') } }); } }).data( "ui-autocomplete" )._renderitem = function( ul, item ) { homecoming $( "<li>" ) .append( "<a>" + item.naam + "</a>" ) .appendto( ul ); };
this code returns in console:
get http://myurl/getklanten.php?term=comp&supplier=false [{"naam":"company name","id":12345}]
however, breaks autocomplete function. without errors. though both functions homecoming exact same data.. help me shed lite on , tell me why happening?
you starting ajax call, aren't using response of call. response
parameter in source
function callback, can trigger after ajax phone call successful.
$('#q').autocomplete({ //source:'getklanten.php' source: function(request, response) { $.ajax({ url: "getklanten.php", data: { term : request.term, supplier : $('#zxc').is(':checked') }, success: function(data){ response(data); }, error: function(){ response(); } }); } });
you must phone call response
callback if encounter error.
see http://api.jqueryui.com/autocomplete/#option-source more information.
javascript jquery autocomplete
No comments:
Post a Comment