2

I am getting the results from Wikipedia API. Although I am trimming the value of the search box before sending it to the API, I am still not able to get the suggestions:

function(results) {
    var availableTags = results[1];//this array is used to give the suggestions and is obatined from the API
    $( "#searchBox" ).autocomplete({
        source: availableTags
    });
 }

If I start with anything other than space/spaces I am able to get the suggestions.

http://codepen.io/shaafiirfan7/full/YqEzjr input "with" first character as "space" input "with" first character as "space" input "without" first character as "space" input without first character as "space"

Irfan Syed
  • 113
  • 2
  • 10
  • Have you considered HTML5 `datalist`? I don't know if it will solve your issue but give it a try. https://developer.mozilla.org/en/docs/Web/HTML/Element/datalist – Roy Apr 05 '16 at 17:35
  • Check your codepen link. It's not taking me to your code. – Roy Apr 05 '16 at 17:37
  • @Roy Codepen link looks good to me. – Joseph Marikle Apr 05 '16 at 17:37
  • Sorry. My mistake. Codepen is alright. – Roy Apr 05 '16 at 17:43
  • @IrfanSyed: This sounds like expected behaviour if you're just sending a raw string to the Wikipedia API. Are you explicitly stripping whitespace before querying or something? – Akshat Mahajan Apr 05 '16 at 17:50
  • @Roy `datalist` it seems this article(http://www.raymondcamden.com/2012/06/14/example-of-a-dynamic-html5-datalist-control/) gives me some aid but I want to know where I am missing while using the "auto-complete" functionality. – Irfan Syed Apr 05 '16 at 17:53
  • @AkshatMahajan yes I am removing the white spaces before querying I am performing the trim action `var value =$("#searchBox").val().trim(); and then in ajax url: "http://en.wikipedia.org/w/api.php?action=opensearch&search="+value` – Irfan Syed Apr 05 '16 at 17:56

0 Answers0