JSON.parse是那里定义的,我在vs2008里js函数里调用了 本帖最后由 yuji821 于 2012-05-23 23:00:31 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那是那里定义的呢,我只引用了最新版的jquery 这个是写在c#中的还是js中的,js中的需要引入json2.js文件,如果c#中的,不知道楼主用的是什么JSON, 是json.net吗 我是写在aspx的 js中我没有下载json.net.DLL,没有引入 json2.js,是用 vs2008页面代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xhr.aspx.cs" Inherits="Demo_xhr" %><!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 runat="server"> <title></title> <script type="text/javascript" src="../js/jquery.js"></script></head><body> <form id="form1" runat="server"> <div> <div id="jsonText"></div> </div> <script type="text/javascript"> function CreateXHR() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } function GetDataFromServer() { try { var req = CreateXHR(); if (req != null) { req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { var jsTextDiv = document.getElementById("jsonText"); var data = JSON.parse(req.responseText); for (var i = 0; i < data.length; i++) { var item = data[i]; var div = document.createElement("div"); div.innerHTML = item.ID + " " + item.UserName + " " + item.RealName + " " + ParseDate(item.Birthday); jsTextDiv.appendChild(div); } } } }; req.open("GET", "../ASHXHandler/PersonInfo.ashx", true); req.send(null); } catch (exception) { alert(exception); } } $(function() { GetDataFromServer(); }); function ParseDate(jsonDate) { var date = new Date(parseInt(jsonDate.substr(6))); return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); } </script> </form> </body></html> 最新的浏览器都内置JSON对象了,可以直接使用,不过,为了兼容性,你i还得引入定义 我的是ie 9,是不是内置了JSON对象了 IE8就开始支持了但是有条件的,参见IE8如何使用原生JSON对象?http://blog.csdn.net/net_lover/article/details/5142499IE8,IE9的标准模式下都支持 请问OnPreRender与Render方法的区别 看看这个使用什么设计模式好! 怎么解决,网站部署后,访问后运行过程中的错误? 如何用验证控件验证复选框的状态 如何在程序中将EXCEL转换成HTML文件 如何防止别的网站引用我网站的图片! 如何知道页面的控件结构, 关于datagrid中checkbox的取值问题!!!给出解决方案,马上给分,在线等!! 关于各大平台API为什么不使用restful的风格 能否用asp.net的後台控件寫一個menu麼 新手求教:ASP.net真的如此不堪吗? Asp.net发邮件验证用户注册,当内容是纯文字时就能发出去,可加上个链接就收不到了,郁闷啊!!
我没有下载json.net.DLL,没有引入 json2.js,是用 vs2008
页面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xhr.aspx.cs" Inherits="Demo_xhr" %><!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 runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="jsonText"></div>
</div>
<script type="text/javascript">
function CreateXHR() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
if (window.ActiveObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
function GetDataFromServer() {
try
{
var req = CreateXHR();
if (req != null) {
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
var jsTextDiv = document.getElementById("jsonText");
var data = JSON.parse(req.responseText);
for (var i = 0; i < data.length; i++) {
var item = data[i];
var div = document.createElement("div");
div.innerHTML = item.ID + " " + item.UserName + " " + item.RealName + " " + ParseDate(item.Birthday);
jsTextDiv.appendChild(div);
}
}
}
};
req.open("GET", "../ASHXHandler/PersonInfo.ashx", true);
req.send(null);
}
catch (exception) {
alert(exception);
}
}
$(function() {
GetDataFromServer();
});
function ParseDate(jsonDate) {
var date = new Date(parseInt(jsonDate.substr(6)));
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}
</script>
</form>
</body>
</html>
我的是ie 9,是不是内置了JSON对象了
但是有条件的,参见
IE8如何使用原生JSON对象?
http://blog.csdn.net/net_lover/article/details/5142499IE8,IE9的标准模式下都支持