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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Character encoding problem in Ajax request

    Simplified example of my problem code:
    PHP Code:

    function search(){

    var 
    search document.getElementById('searchstring').value;
    xmlHttp=GetXmlHttpObject()

        if (
    xmlHttp==null)
        {
            
    alert ("Browser does not support HTTP Request")
            return
        }
        var 
    url="search.php"
        
    url=url+"?string="+search
        url
    =url+"&sid="+Math.random()
        
    xmlHttp.onreadystatechange=stateChanged
        xmlHttp
    .open("GET",url,true)
        
    xmlHttp.send(null)

    search.php
    Code:
    PHP Code:
    <?php header('Content-Type: text/html; charset=utf-8');
    $searchstring mysql_escape_string($_GET['string']);
    echo 
    $searchstring;
    ?>
    In firefox everything works fine, but in Internet Explorer if I send a searchvalue like öööööö, it echos this �� . If I put $searchstring = utf8_encode($searchstring); in search.php, then it works in Explorer, but of course not in firefox. What would be a good way to fix this.

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    you can try this on the search.php

    PHP Code:
    <?PHP
    //Drop the header as it is NOT required:
    echo urldecode($searchstring);

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion, but it did not help.

  • #4
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The fix was so simple

    var search = encodeURIComponent(document.getElementById('searchstring').value);


  •  

    Posting Permissions

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