Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:12:02+00:00 2026-06-16T05:12:02+00:00

I have run into some problems with displaying data in jquery ui autocomplete, when

  • 0

I have run into some problems with displaying data in jquery ui autocomplete, when i display the text, it is not utf-8 encoded, despite my db and page are using utf-8.

Also when i try to display it any other way, it show normally with the right encoding.

The jquery ui script.

<script type="text/javascript" charset="utf-8">
$(function() {
    function log( message ) {
        $( "<div>" ).text( message ).prependTo( "#log" );
        $( "#log" ).scrollTop( 0 );
    }

    $( "#items" ).autocomplete({
        source: "getSurgestedItems.php",
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.value + " aka " + ui.item.id :
                "Nothing selected, input was " + this.value );
        }
    }).data("autocomplete")._renderItem = function(ul, item){
        return $("<li>")
            .data("item.autocomplete", item)
            .append("<a>" + item.value + "<br>" + item.desc + "</a>")
            .appendTo(ul);
    };
});
</script>

The php script getting the items.

while ($row = $result->fetch_assoc()) {
$i++;
if(!$first){
    $json .=',';
}
else{
    $first = false;
}

$name = addslashes($row['name']);
$desc = mb_substr(addslashes($row['description']), 0, 60, 'UTF-8');

$desc .= '...';

$json .='{"value" : "'.$name.'",
        "desc" : "'.$desc.'"}';
}
$json .=']';

echo $json;

Now like i said I have tried to displaying the data, in every way i can think of and it is only with the autocomplete feature it is displayed wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:12:04+00:00Added an answer on June 16, 2026 at 5:12 am

    SaschaM78 comment got me looking in the right direction, while looking into json_encode, I discovered that it would only work with utf-8, which led me to try and encode each string to utf-8, using mb_convert_encoding, which have solve my problem, it works fine now.

    The new php code.

    $json = array();
    
    while ($row = $result->fetch_assoc()) {
    
    $name = mb_convert_encoding($row['name'], 'UTF-8');
    $desc = mb_convert_encoding(substr($row['description'], 0, 60), 'UTF-8');
    
    $desc .= '...';
    
    $json[] = array('value' => $name, 'desc' => $desc); 
    }
    
    echo json_encode($json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing code for a blackjack game and have run into some problems. I
As a spin of of an earlier question, I have run into some problems
I'm trying to build my first generic list and have run into some problems.
I am fixing some problems with a legacy system and have run into a
I am using djangoappengine and I think have run into some problems with the
I'm just starting to learn Xcode, and have run in to some problems... I've
I have run into some trouble with the gd library's imagefilledpolygon() . For some
I am creating a small Yahtzee game and i have run into some regex
I am trying to build a responsive email template but have run into some
I am using notepad++ to do some date conversions but have run into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.