jQuery UI autocomplete ajax with multiple values -
i've checked several solutions this:
jquery ui autocomplete multiple values in textbox
jquery ui autocomplete multiple values
with no success. have jquery ui autocomplete working exception of search phrases spaces in them. instance, i'll search "real" , list of results if enter "real estate" bombs out after "real ".
here's current working code adding space in textbox:
<script type="text/javascript"> $(document).ready(function () { /* auto complete menu search option */ $("#txtsearchprogram").autocomplete({ source: function (request, response) { $.ajax({ type: 'get', url: '/specialpages/program-autocomplete.aspx', data: { 'searchtext' : encodeuricomponent(request.term), 'langspecific' : '1' }, datatype: 'json', success: function(jsondata) { response(jsondata); } }); }, delay: 0, minlength: 2, open: function() { $(this).autocomplete("widget") .appendto("#autocomplete-results") .css("position", "static")}, focus: function( event, ui ) { $(this).attr("placeholder", ui.item.label); return false; }, select: function (event, ui) { event.preventdefault(); var url = ui.item.value; if (url != '#') { location.href = url; } } }); });
here code tried above links continue receive "uncaught typeerror: cannot read property 'autocomplete' of undefined" error
<script type="text/javascript"> $(document).ready(function () { /* auto complete menu search option */ $("#txtsearchprogram").autocomplete({ source: function (request, response) { $.ajax({ type: 'get', url: '/specialpages/program-autocomplete.aspx', data: { 'searchtext' : encodeuricomponent(request.term) }, datatype: 'json', success: function(jsondata) { var re = $.ui.autocomplete.escaperegex(request.term); // errors out here var matcher = new regexp( "^" + re, "i" ); response($.grep(jsondata, function(item){return matcher.test(item.value);}) ); } }); }, delay: 0, minlength: 2, open: function() { $(this).autocomplete("widget") .appendto("#autocomplete-results") .css("position", "static")}, focus: function( event, ui ) { $(this).attr("placeholder", ui.item.label); return false; }, select: function (event, ui) { event.preventdefault(); var url = ui.item.value; if (url != '#') { location.href = url; } } }); });
when debug i'm not getting detail (not strong front end dev) other error mentioned.
after further testing found issue placed , encoded parameters. code below started with:
<script type="text/javascript"> $(document).ready(function () { /* auto complete menu search option */ $("#txtsearchprogram").autocomplete({ source: function (request, response) { $.ajax({ type: 'get', url: '/specialpages/program-autocomplete.aspx', data: { 'searchtext' : encodeuricomponent(request.term), 'langspecific' : '1' }, // problem here datatype: 'json', success: function(jsondata) { response(jsondata); } }); }, delay: 0, minlength: 2, open: function() { $(this).autocomplete("widget") .appendto("#autocomplete-results") .css("position", "static")}, focus: function( event, ui ) { $(this).attr("placeholder", ui.item.label); return false; }, select: function (event, ui) { event.preventdefault(); var url = ui.item.value; if (url != '#') { location.href = url; } } }); }); </script>
and ended with. note removed data
attribute , created query string.
<script type="text/javascript"> $(document).ready(function () { /* auto complete menu search option */ $("#txtsearchprogram").autocomplete({ source: function (request, response) { $.ajax({ type: 'get', url: '/specialpages/program-autocomplete.aspx?searchtext=' + encodeuricomponent(request.term) + '&langspecific=1', // resolved datatype: 'json', success: function(jsondata) { response(jsondata); } }); }, delay: 0, minlength: 2, open: function() { $(this).autocomplete("widget") .appendto("#autocomplete-results") .css("position", "static")}, focus: function( event, ui ) { $(this).attr("placeholder", ui.item.label); return false; }, select: function (event, ui) { event.preventdefault(); var url = ui.item.value; if (url != '#') { location.href = url; } } }); }); </script>
Comments
Post a Comment