注意浏览时。看看浏览器的CharSet一定要选择在“简体中文GB2312” 处。<?php
define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gb2312' );
define('DEBUG', true);
require_once("xajax/xajax.inc.php");
require_once("mssql.class.php");$xajax = new xajax();
if(DEBUG) $xajax->debugOn();
//$xajax->setCharEncoding(XAJAX_DEFAULT_CHAR_ENCODING);
$xajax->decodeUTF8InputOn();
$xajax->registerFunction("show");function show($name)
{
// $Response = new xajaxResponse(XAJAX_DEFAULT_CHAR_ENCODING);
$Response = new xajaxResponse();
$db = new mssql; //创建数据库类
$s = "";
$sqlstr = "select top 10 * from jb01 where name like '" . $name . "%'";
$rs = $db->query($sqlstr);
while($r = $db->fetch_row($rs)){
$s .= $r[1] . " | " .$r[2] . "</br>" ;
}
$db->db_close(); $Response->addAssign("div1","innerHTML",$name . "</br>");
$Response->addAppend("div1","innerHTML", $s );
return $Response->GetXml();
$xajax->processRequests();
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>My PHP MySql Class </title><?php
$xajax->printJavascript("xajax");
?>
</head><body>
请输入:
<input type="name" name="logclass" value="">
<input type="button" name="submit" onclick="cg();" value="post">
<script language="javascript">
function cg()
{
xajax_show(document.getElementById('logclass').value);
}
</script>
<br><div id="div1" name="div1">
</div>
</body>
define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gb2312' );
define('DEBUG', true);
require_once("xajax/xajax.inc.php");
require_once("mssql.class.php");$xajax = new xajax();
if(DEBUG) $xajax->debugOn();
//$xajax->setCharEncoding(XAJAX_DEFAULT_CHAR_ENCODING);
$xajax->decodeUTF8InputOn();
$xajax->registerFunction("show");function show($name)
{
// $Response = new xajaxResponse(XAJAX_DEFAULT_CHAR_ENCODING);
$Response = new xajaxResponse();
$db = new mssql; //创建数据库类
$s = "";
$sqlstr = "select top 10 * from jb01 where name like '" . $name . "%'";
$rs = $db->query($sqlstr);
while($r = $db->fetch_row($rs)){
$s .= $r[1] . " | " .$r[2] . "</br>" ;
}
$db->db_close(); $Response->addAssign("div1","innerHTML",$name . "</br>");
$Response->addAppend("div1","innerHTML", $s );
return $Response->GetXml();
$xajax->processRequests();
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>My PHP MySql Class </title><?php
$xajax->printJavascript("xajax");
?>
</head><body>
请输入:
<input type="name" name="logclass" value="">
<input type="button" name="submit" onclick="cg();" value="post">
<script language="javascript">
function cg()
{
xajax_show(document.getElementById('logclass').value);
}
</script>
<br><div id="div1" name="div1">
</div>
</body>
当XMLHttpRequest遇到他不能识别的语言编码而有强制转换成utf-8或unicode编码时,其后果是可想而知的。按理xajax的作者是应该注意到这个事实,并采去了相应措施的。一般在自行开发的ajax应用中是需要将传递的参数用js的encodeURIComponent函数显式的转换成utf-8编码的url编码串。这样服务器端经自动url解码后的参数是utf-8编码的,可以根据需要转换成相应的编码值得注意的是,js的escape函数将产生unicode编码的url编码串。但是几乎所有的web服务器都不能正确的识别unicode编码串,包括iis。尽管unicode编码方案是微软提出的由于不使用xajax,所以没有仔细查看xajax代码。只能提出一些原则上的意见。
其实自己书写ajax工具包要来得简单的多。
直接用GB2312
蛮好用的。