Jquery autocomplete not updating -


i'm making ajax call populate input field autocomplete. autocomplete not being updated, json response being generated correctly, problem results of autocomplete not being updated. strange autocomplete works on localhost, when try on web server, doesn't work. below code:

<input name="label" class="form-control ui-autocomplete-input ui-autocomplete-loading" type="text" id="label" autocomplete="off"> 

here javascript of autocomplete:

    $(document).ready(function() {      $('#label').autocomplete({         minlength: 3,         source: function(request, response){             var loadtitles = "<?php echo $this->html->url(array('controller' => 'titles', 'action' => 'getajax'))?>/" + request.term;             $.getjson(loadtitles, function(data){                 response(data);             });         },         focus: function(event, ui){             $('#label').val(ui.item.label);             return false;         },         select: function(event, ui){             $('#label').val(ui.item.label);             $('#label').val(ui.item.id);             return false;         }     }).data("ui-autocomplete")._renderitem = function( ul, item ){         return $( "<li>" )             .append( "<a>" + item.label + " [<strong>" + item.description + "</strong>]</a>" )             .appendto( ul );     };  }); 

as mentioned earlier, ajax function working correctly (getajax function), implemented on cakephp framework, , returning json result correctly, problem input autocomplete not rendering results.

after struggling found issue. problem value on json had lot of white spaces @ end of it, following function gave unexpected token error:

$.getjson(loadtitles, function(data){    response(data);  }); 

i added .fail function it, , received unexpected token error white spaces.

another problem using chrome, , use kind of trim rid of white spaces, couldn't see it. tried debug on firefox, using firebug plugin, , in browser able see white spaces on 1 of json elements. deleted white spaces on database, , autocomplete started working charm.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -