...

View Full Version : Ajax livesearch weird behavior...



richard300
12-11-2011, 02:07 PM
Hi,

I used the code on the following example:
http://www.w3schools.com/php/php_ajax_livesearch.asp

Instead of xml I use mysql but it works the same way.


My problem is with this character '#' (shift 3 - on my keyboard, or otherwise known as 'sharp').

Some of the words in my database table contain this character but when I type it, it acts like nothing was typed.


Any idea on what to do to make this work like any other character?

Thanks

Amphiluke
12-11-2011, 02:26 PM
What oversight I see in their example is they do not encode a query string.
It should look like follows:

function showResult(str)
{

// ..... skipped

str = encodeURIComponent(str).replace(/%20/g, "+"); // <-- !
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();

And in the PHP File


//get the q parameter from URL
$q=urldecode($_GET["q"]); // <--



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum