sanders_yao
版主
  
or2 =333
UID 30286
精华
0
积分 11786
帖子 4970
金钱 11783 喜悦币
威望 0
人脉 3
阅读权限 100
注册 2004-7-23 来自 北京 菜户营
状态 离线
|
请教ajax乱码的js解决方案
刚才测试的时候出现了一个问题 希望大家帮我解决一下
我建立了一个文件内容如下:
{
"item" : [
{
"title" : encodeURIComponent("往事如烟(我第一次“谈朋友”)"),
"link" : "http://www.chinalabs.com/view/xueshu/135550.html",
"author" : "TOM科技",
"pubDate" : "2006-4-13 17:07:49"
},
{
"title" : encodeURIComponent("往事如烟(我第一次“谈朋友”)"),
"link" : "http://www.chinalabs.com/view/xueshu/135550.html",
"author" : "TOM科技",
"pubDate" : "2006-4-13 17:07:49"
}
]
}
但是我在另一个测试页面请求的时候就会出现乱码,请先看下我的代码片断:
function loader(){
var req = getXmlHTTPRequest();
req.open("get", "http://localhost/test.txt", false);
req.send();
eval("var strReq = " + req.responseText);
var strOutput = "";
for(var i = 0;i < strReq["item"].length;i ++){
strOutput += "<tr><td>" + strReq["item"]["title"] + "</td></tr>";
}
strOutput = "<table border=\"1\">" + decodeURIComponent(strOutput) + "</talbe>";
document.getElementById("console").innerHTML = strOutput;
alert(strOutput);
}
window.onload = function(){
document.getElementById("test").onclick = loader;
}
</script>
<body>
<div id="test" style="background-color:#CCCCCC; width:100px; height:100px;"></div>
<div id="console" style="width:500px; border:solid #000000 1px;"></div>
</body>
</head>
有没有使用js解决这种乱码的方法
|  最近写的一些代码都会在以下地址发布,有兴趣的来批:
http://www.phpx.com/happy/thread-131368-1-1.html |
|