GautamD31
GautamD31

Reputation: 28753

Autocomplete not allowing spaces

I am using autocomplete in my site like this:

$(document).ready(function(){           
$('input[type="text"]').each(function(){
    var $this = $(this);
        $this.autocomplete({              
            minLength: 1,                                               
        source: "{site_url}publish/my_autocomplete?key=" + $this.attr('id')
        })
    });     
})

It is working fine but when there is a word 'harley motor' and if I have typed 'ey ' with space it is not displaying. Any suggestions as to how I can select harley motor by just typing ey with a trailing space?

Upvotes: 3

Views: 2733

Answers (3)

Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

The URL needs to be escaped, since not only you have the issue:

Blank spaces in ajax request with jquery

You need to escape:

source: escape("{site_url}publish/my_autocomplete?key=" + $this.attr('id'))

Upvotes: 2

anomaaly
anomaaly

Reputation: 841

I'm not sure by just looking at your code. But it seems like you might be having problems posting spaces. Try using encodeURIComponent to encode your spaces before posting to the server.

Upvotes: 1

Murali Murugesan
Murali Murugesan

Reputation: 22619

I would suggest you to find where the problem is, server side or client side..

If you get Request.Params["term"] value in server side that contains the user entered data with space, then you need to think about where the server side logic is error.

Otherwise, it might be an issue in client side, somewhere the entered text got spaces removed.

Note: Request.Params here I used is specific to ASP.Net and I am not sure about what server side technology you are using. But every language might have a equivalent code to check the request value

Upvotes: 0

Related Questions