注意浏览时。看看浏览器的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>

解决方案 »

  1.   

    很遗憾,无论页面语言被设置成什么。XMLHttpRequest都将以utf-8或unicode编码向上传递数据。
    当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工具包要来得简单的多。
      

  2.   

    嗯, 那有没有自己写的ajax实例?
      

  3.   

    我一直用 xajax 用着挺好。 没有用UTF8,
    直接用GB2312 
    蛮好用的。
      

  4.   

    ajax实在没有iframe好用,忽略……
      

  5.   

    个人建议:在js客户端自己实现一个编码机制,然后服务器端实现响应的解码机制,脱离UTF-8的直接范围。
      

  6.   

    问题是我自己做服务器装ICONV可以,但是如果租用怎么办?