Ajax garbled problem (imitation Baidu search page), online solution, heroes have the speed to help

Source: Internet
Author: User
Garbled Ajax

This garbled how to solve!!! My code is all posted:
 
  0) {$sql = "Select username from Phpcms_member WHERE username like '". $queryString. " % '  LIMIT 0,15 '; echo $sql; $query = mysql_query ($sql), while ($result = Mysql_fetch_array ($query)) {$value = $result [' Username '];echo '
  • '. $value. '
  • ';}}? >


    Htm:
     
      Ajax Search Capabilities



    Reply to discussion (solution)

    Someone please help look, O (∩_∩) o Thank you

    Someone please help look, O (∩_∩) o Thank you

    Ajax for Chinese processing, you'd better do a bit of conversion, because the coding problem caused by

    Because you have the header (' CONTENT-TYPE:TEXT/HTML;CHARSET=GBK ');
    So Ajax will interpret the returned content as GBK
    But Ajax always sends data out of Utf-8.
    So you $queryString = $_post[' queryString ');
    Get the data that is UTF-8 encoded when you echo $sql; , the contents of the Utf-8 as GBK sent out, so there is garbled
    For this you need
    $queryString = Iconv (' utf-8 ', ' GBK ', $_post[' queryString ');
    Turn the data from Ajax to code

    Because you have the header (' CONTENT-TYPE:TEXT/HTML;CHARSET=GBK ');
    So Ajax will interpret the returned content as GBK
    But Ajax always sends data out of Utf-8.
    So you $queryString = $_post[' queryString ');
    Get the data that is UTF-8 encoded when you echo $sql; , the contents of the Utf-8 as GBK sent out, so there is garbled
    For this you need
    $queryString = Iconv (' utf-8 ', ' GBK ', $_post[' queryString ');
    Turn the data from Ajax to code

    Thank xuzuning once again to solve my problem!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.