|
|
|
ปัญหา ajax กับการใช้ภาษาไทยค่ะ ลองดูจากกระทู้เก่าๆแล้ว |
|
|
|
|
|
|
|
อันนี้เป็น ajax auto field ค่ะ ข้อมูลใน textbox ที่ query มาจาก database เป็นภาษาไทยค่ะ
แต่มันขึ้นเป็นภาษาต่างดาวค่ะ มีวิธีแก้ยังไงบ้างคะ
Code (PHP)
<?
ob_start();
session_start();
if($_SESSION["adminlogin"]=="")
{
header('location:login.php');
exit();
} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?
$link = mysql_connect("localhost", "root", "password");
mysql_query("use project;");
mysql_query("set NAMES tis620");
?>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>Add data's nutrient</title>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(fNutrientID,fUnit) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'addnutrition_getfill.php';
var pmeters = "tNutrientID=" + encodeURI( document.getElementById(fNutrientID).value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
//if(HttPRequest.readyState == 3) // Loading Request
//{
//document.getElementById(fProductName).innerHTML = "..";
//}
if(HttPRequest.readyState == 4) // Return Request
{
var myProduct = HttPRequest.responseText;
if(myProduct != "")
{
var myArr = myProduct.split("|");
document.getElementById(fUnit).value = myArr[0];
//document.getElementById(fPrice).value = myArr[1];
}
}
}
}
</script>
<script type="text/javascript">
function senddata()
{
if(document.getElementById('cat1').value.length == 0)
{
alert ('เลือกผลิตภัณฑ์ด้วยค่ะ');
return false;
}
document.getElementById('submit').disabled = true;
return true;
}
function AddOk(pathfile)
{
document.getElementById('showdetail').innerHTML = 'เพิ่มข้อมูลเสร็จเรียบร้อยแล้ว';
document.getElementById('submit').disabled = false;
document.getElementById('AddPForm').reset();
return true;
}
</script>
</head>
<? include "head.php"; ?>
<table width=1366>
<tr><td width=266 bgcolor=#F0FFF0 valign=top>
<ul>
<a href=adddata_admin.php><h3>Add product's data</h3></a><br />
<a href=updatedata_admin.php><h3>Edit-Delete product's data</h3></a><br />
<a href=addnutrition_admin.php><h3>Add product's nutrient</h3></a><br />
<a href=adddate_admin.php><h3>Add product's date</h3></a><br />
<a href=delete_admin.php><h3>Delete product's date</h3></a><br />
<a href=addcom_admin.php><h3>Add computer</h3></a><br />
<a href=updatecom_admin.php><h3>Edit-Delete computer</h3></a><br />
<a href=addstandard_admin.php><h3>Add standard</h3></a><br />
<a href=updatestandard_admin.php><h3>Edit-Delete standard</h3></a><br />
<a href=addnutrient_admin.php><h3>Add nutrient</h3></a><br />
<a href=updatenutrient_admin.php><h3>Edit-Delete nutrient</h3></a><br />
<a href=homepage.php><h3>Homepage</h3></a><br />
<a href=logout.php><h3>Log out</h3></a><br />
</ul>
</td>
<td width=1200 bgcolor=#C1FFC1 valign=top>
<iframe id="uploadtarget" name="uploadtarget" src="" style="width:0px;height:0px;border:0"></iframe>
<script>
function setFocus(){
frm.nut1.focus();
}
</script>
<body onLoad="setFocus()">
<form name="frm" id="AddPForm" method="post" enctype="multipart/form-data" action="addnutrient.php" onsubmit="return senddata();" target="uploadtarget">
<H2><B>ข้อมูลทางโภชนาการของผลิตภัณฑ์</B></H2>
ชื่อผลิตภัณฑ์ :
<select name="cat" id="cat">
<option value=""></option>
<?
$sql = "select ProductID,ProductName,Size from product order by ProductID ASC";
$sqlquery = mysql_query($sql);
while ($result = mysql_fetch_array($sqlquery))
{ ?>
<option value="<?=$result["ProductID"];?>">
<?=$result["ProductName"];?> - <?=$result["Size"];?>
</option>
<? } ?>
</select>
<p>
คุณค่าทางโภชนาการ : <select name="cat1" id="cat1" OnChange="JavaScript:doCallAjax('cat1','txtunit1');">
<option value="">--Please select--</option>
<?
$sql = "select NutrientID,NutrientName from nutrients order by NutrientID ASC";
$sqlquery = mysql_query($sql);
while ($result = mysql_fetch_array($sqlquery))
{ ?>
<option value="<?=$result["NutrientID"];?>">
<?=$result["NutrientName"];?>
</option>
<? } ?>
</select>
ปริมาณ : <input type="text" name="qty1" id="qty1"/> หน่วย :
<input type="text" name="txtunit1" id="txtunit1" />
<p> <select name="cat2" id="cat2" OnChange="JavaScript:doCallAjax('cat2','txtunit2');">
<option value="">--Please select--</option>
<?
$sql = "select NutrientID,NutrientName from nutrients order by NutrientID ASC";
$sqlquery = mysql_query($sql);
while ($result = mysql_fetch_array($sqlquery))
{ ?>
<option value="<?=$result["NutrientID"];?>">
<?=$result["NutrientName"];?>
</option>
<? } ?>
</select>
ปริมาณ : <input type="text" name="qty2" id="qty2" /> หน่วย : <input type="text" name="txtunit2" id="txtunit2" />
<p> <select name="cat3" id="cat3" OnChange="JavaScript:doCallAjax('cat3','txtunit3');">
<option value="">--Please select--</option>
<?
$sql = "select NutrientID,NutrientName from nutrients order by NutrientID ASC";
$sqlquery = mysql_query($sql);
while ($result = mysql_fetch_array($sqlquery))
{ ?>
<option value="<?=$result["NutrientID"];?>">
<?=$result["NutrientName"];?>
</option>
<? } ?>
</select>
ปริมาณ : <input type="text" name="qty3" id="qty3" /> หน่วย : <input type="text" name="txtunit3" id="txtunit3" />
<p> <select name="cat4" id="cat4" OnChange="JavaScript:doCallAjax('cat4','txtunit4');">
<option value="">--Please select--</option>
<?
$sql = "select NutrientID,NutrientName from nutrients order by NutrientID ASC";
$sqlquery = mysql_query($sql);
while ($result = mysql_fetch_array($sqlquery))
{ ?>
<option value="<?=$result["NutrientID"];?>">
<?=$result["NutrientName"];?>
</option>
<? } ?>
</select>
ปริมาณ : <input type="text" name="qty4" id="qty4" /> หน่วย: <input type="text" name="txtunit4" id="txtunit4" />
<p>
<input type="submit" name="submit" value="Submit" id="submit">
<input type="reset" name="cancle" value="Reset" id="reset">
</form><p>
<span id="showdetail"></span>
</td></tr></table>
</body>
</html>
Tag : PHP, MySQL, JavaScript, Ajax
|
|
|
|
|
|
Date :
2012-04-16 01:16:25 |
By :
Supergirl |
View :
1378 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอน query ใส่ บรรทัดนี้ไปด้วยดิครับ
mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=tis620");
mysql_query("SET character_set_connection=tis620");
ลองดูนะครับ
ปล. ทำไมไม่ใช้ UTF8 ละครับ เจ้า tis620 หนะเก่าแล้วนะครับ
|
|
|
|
|
Date :
2012-04-16 01:29:55 |
By :
AK |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ได้แล้วค่ะ ใส่
Code (PHP)
header("Content-Type:test/plain;charset=tis-620");
เข้าไป
ตอบพี่ข้างบนนะคะ
คือ พอนหนูใช้ utf-8 มันเป็นอย่างนี้อ่ะค่ะ ��ͼ�Ե�ѳ��
|
|
|
|
|
Date :
2012-04-16 01:39:37 |
By :
Supergirl |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|