473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

utf-8 problem with ajax

Hi

I want to use ajax to connect to database and echo some data in my page, I wrote these two codes that can handle my need:

index.php
-----------------------------------------
[PHP]<?php

//This file is text.php

mysql_connect("localhost", "root", ""); //Connect to the mysql server with your host (most likely localhost), username, and password
mysql_select_db("dictionary"); //Select your database by name

$page = $_GET["page"]; //This is the variable we retrieve through GET to know which row of content to retrieve

$sql = "SELECT * FROM table1 WHERE f1 = '$page'"; //This is the text of the query. We will select the content field from the table ‘pages’ where the page field has the same value as the one we want to retrieve

$query = mysql_query($sql) or die(mysql_error()); //Make the actual query

if( mysql_num_rows($query) == 1 ) //Check to see if we found 1 row with that page name
{
$r=mysql_fetch_assoc($query); //Set a mysql fetching variable for the query
echo $r["f2"]; //Echo out the content of the page we want
}
else
{
echo "Sorry, that page was not found."; //Otherwise, echo out an error message saying the page was not found
}

?>
[/PHP]--------------------------------------------
text.php
---------------------------------------------
[PHP]<?php

//This file is text.php

mysql_connect("localhost", "root", ""); //Connect to the mysql server with your host (most likely localhost), username, and password
mysql_select_db("mydatabse"); //Select your database by name

$page = $_GET["page"]; //This is the variable we retrieve through GET to know which row of content to retrieve

$sql = "SELECT * FROM table1 WHERE f1 = '$page'"; //This is the text of the query. We will select the content field from the table ‘pages’ where the page field has the same value as the one we want to retrieve

$query = mysql_query($sql) or die(mysql_error()); //Make the actual query

if( mysql_num_rows($query) == 1 ) //Check to see if we found 1 row with that page name
{
$r=mysql_fetch_assoc($query); //Set a mysql fetching variable for the query
echo $r["f2"]; //Echo out the content of the page we want
}
else
{
echo "Sorry, that page was not found."; //Otherwise, echo out an error message saying the page was not found
}

?>
[/PHP]------------------------------------------

I works good, when my database is normal, but for utf-8 data it gives me ??? instead of the words retrieved from database, I believe there should be a code that I missed that would show the utf-8 data in JAVA script.

will someone help me, thank/
Feb 23 '08 #1
1 2951
acoder
16,027 Expert Mod 8TB
Either set the header in PHP or with setRequestHeader("content-type"...) via the XMLHttpRequest object.
Feb 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: EU citizen | last post by:
Do web pages have to be created in unicode in order to use UTF-8 encoding? If so, can anyone name a free application which I can use under Windows 98 to create web pages?
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
16
by: lawrence | last post by:
I was told in another newsgroup (about XML, I was wondering how to control user input) that most modern browsers empower the designer to cast the user created input to a particular character...
22
by: Martin Trautmann | last post by:
Hi all, is there any kind of 'hiconv' or other (unix-like) conversion tool that would convert UTF-8 to HTML (ISO-Latin-1 and Unicode)? The database output is UTF-8 or UTF-16 only - Thus almost...
6
by: Tony Nelson | last post by:
I'd like to have a fast way to validate large amounts of string data as being UTF-8. I don't see a fast way to do it in Python, though: unicode(s,'utf-8').encode('utf-8) seems to notice at...
2
by: Shailendra Batham | last post by:
Hi there XML Gurus ;) I am trying to use XML Serialization to create a xml from a class, this is the output which I get when I create the XML and put in a string variale. "<?xml version=\"1.0\"...
4
by: Cott Lang | last post by:
ERROR: could not convert UTF-8 character 0x00ef to ISO8859-1 Running 7.4.5, I frequently get this error, and ONLY on this particular character despite seeing quite a bit of 8 bit. I don't really...
1
by: R | last post by:
Hi All, I'm using UTF-8 encoding for my PHP scripts, output is also UTF-8. all files have UTF-8 BOM: 0xEF 0xBB 0xBF at the beginning I have PHP Version 5.1.2 on WinNT and PHP 5.1.1 on Gentoo...
4
by: shreshth.luthra | last post by:
Hi All, I am having a GUI which accepts a Unicode string and searches a given set of xml files for that string. Now, i have 2 XML files both of them saved in UTF-8 format, having characters...
6
by: docbook.xml | last post by:
I have the following in the XHTML 1.0 Strict page: <meta http-equiv="Content-Type" content="text/html;charset=utf-32" /> However W3 validator complains that "The character encoding specified in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.