Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ajax livesearch weird behavior...

    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

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    What oversight I see in their example is they do not encode a query string.
    It should look like follows:
    Code:
    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
    PHP Code:
    //get the q parameter from URL
    $q=urldecode($_GET["q"]); // <-- 
    I am still learning English


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •