views:

226

answers:

3

I'm using the following code to post to the server which is then sent to a MYSQL query to find matches via search.

$.ajax({
url: '/search/spotlight/',
data: "q=" + $(this).val(),
success: function(data) {
}
});

When Q's val has spaces in it, it's creating problems. I'm wondering if I'm handling this correctly? Do I need to encode the value in the AJAX call? Or is this a problem on my backend, which is ColdFusion

Right now JQUERY is posting the following to the server: /search/spotlight/?q=FirstName%20LastName

is this right?

+5  A: 

/search/spotlight/?q=FirstName%20LastName is a valid url string. My guess is your server side script needs to handle things better.

BTW you don't need to build the query string yourself jquery can do it for you:

$.ajax({
url: '/search/spotlight/',
data: {"q": $(this).val()},
success: function(data) {
}
});
PetersenDidIt
+1  A: 

it is right ... %20 means space

but you should set the data like this

data: {'q': $(this).val()}
Gaby
+4  A: 

Looks ok on the client side. Just use URLDecode on the string in ColdFusion, to turn %20 to space (and other special characters as well).

Traveling Tech Guy