本帖最后由 yuji821 于 2012-05-23 23:00:31 编辑

解决方案 »

  1.   

    那是那里定义的呢,我只引用了最新版的jquery
      

  2.   

    这个是写在c#中的还是js中的,js中的需要引入json2.js文件,如果c#中的,不知道楼主用的是什么JSON, 是json.net吗
      

  3.   

    我是写在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>
      

  4.   

    最新的浏览器都内置JSON对象了,可以直接使用,不过,为了兼容性,你i还得引入定义
      

  5.   


    我的是ie 9,是不是内置了JSON对象了
      

  6.   

    IE8就开始支持了
    但是有条件的,参见
    IE8如何使用原生JSON对象?
    http://blog.csdn.net/net_lover/article/details/5142499IE8,IE9的标准模式下都支持