请教大侠 获取JSON返回数据问题

xyy7309 2015-02-19 11:27:00
<script type="text/javascript">
<!--
var xmlhttp;
// 创建XMLHTTPRequest对象
function createXMLHTTPRequest()
{
if(window.ActiveXObject)//②如果当前浏览器为IE
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHTTPRequest)//③如果是其他浏览器
{
xmlhttp = new XMLHTTPRequest();
}
}

function getInfo()
{
var bh =document.getElementById("bh").value;
var name=document.getElementById("name").value;

createXMLHTTPRequest();
if ((bh == null) || (bh == "")) return;
var url = "1.asp?bh=" + escape(bh);
url=url + "&name=" + name;
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = returnInfo;
xmlhttp.send(null);
}

function returnInfo()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var info = xmlhttp.responseText;
// shownr.innerHTML = info;
//返回 info = {"traderates_get_response":{"trade_rates":{"trade_rate":[{"content":"很好!","nick":"平地","result":"good","valid_score":false},{"content":"不错!","nick":"平地","result":"good","valid_score":true}]},"total_results":2}}

showscore.innerHTML = valid_score;
shownick.innerHTML = nick;
showcontent.innerHTML = content;
showresult.innerHTML = result;
}
}
-->
</script>
<input name="bh" type="hidden" id="bh" >
<input name="name" type="hidden" id="name" >
<body onLoad="getInfo()">

页面输出,如:
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>nick</td>
<td>score</td>
<td>result</td>
<td>result</td>
</tr>
<tr>
<td><span id="shownick"></span>
</td>
<td><span id="showscore"></span>
</td>
<td><span id="showresult"></span>
</td>
<td><span id="showcontent"></span>
</td>
</tr>
</table>

</body>
</html>

...全文
145 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyy7309 2015-02-22
  • 打赏
  • 举报
回复
引用 1 楼 net_lover 的回复:
你的问题是?
请教,如何获取返回数据的输出?
孟子E章 2015-02-20
  • 打赏
  • 举报
回复
你的问题是?

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧