<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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" language="javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
     function over(evt)
     {
        var x,y;
        var offsetX=10,offsetY=20;
        var scrollTop = $(window).scrollTop();
        var scrollLeft = $(window).scrollLeft();
        x=evt.clientX +scrollLeft;
        y=evt.clientY ;
        if (x-scrollLeft+ $("#showLayers").outerWidth()+offsetX> $(window).width()) {
           x = x - $("#showLayers").outerWidth() - 2 * offsetX;}
  
        if ((y+$("#showLayers").outerHeight()+offsetY)>$(window).height()) {
        y = $(window).height()-$("#showLayers").outerHeight()-offsetY;}
    x=x+offsetX;
    y=y+offsetY;
    $("#showLayers").css({ "top": (y +scrollTop) + "px", "left": x + "px" });

    $("#showLayers").html("<div id=\"ShowContentTitle\">内容读取中</div>"
        +"<img src=\"images/reading.gif\" border=\"0\" id=\"ShowContentImg\" alt=\"读取中\" />"
        +"<div id=\"ShowConfig\"></div>").show();     $.getJSON("GetInfo.aspx?id=" + $(this).attr("pid"),function(data)
    {
    if(data.state=='True')
    {
        $("#showLayers").html("<div id=\"ShowContentTitle\">" + data[0].showTitle + "</div>"
            +"<img src=\"" + data[0].showImg + "\" border=\"0\" id=\"ShowContentImg\"/ width=\"230\" height=\"280\">"
            +"<div id=\"ShowConfig\">" + data[0].showTitle + "</div>");
    }
    else
    {alert(data.reason);}
    });
}


function out()
{
    $("#showLayers").hide();
}
    </script>
</head>
<body>
    <div class="libox" style="width:400px;">
        <ul>
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <li><a onmouseover="over(event)" onmouseout="out()" name="prolist" pid="<%#DataBinder.Eval(Container.DataItem, "ID")%>" href="#">
                        ·<%#DataBinder.Eval(Container.DataItem, "showTitle")%></a></li>
                </ItemTemplate>
            </asp:Repeater>
        </ul>
    </div>
    <div id="showLayers" style="display: none; position:absolute;">
       
    </div>
</body>
</html>
//GetInfo.aspx 后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using System.Text;public partial class GetInfo : System.Web.UI.Page
{
    string showID;    public string str = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }
    void Bind()
    {        if (!string.IsNullOrEmpty(Request.Form["id"]))
        {
            showID = Request.Form["id"].ToString();
            AccessDB obj = new AccessDB();
            string sql = "select ID,showTitle,showImg from ShowInfo where ID=" + showID;
            DataTable dt = new DataTable();
            dt = obj.ExectueSql(sql);//查询返回datatable
            System.Text.StringBuilder StrBui = new System.Text.StringBuilder();            // --------------------------把返回的datatable dt转换为Json字符串
            StrBui.Append("[");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                StrBui.Append("{");
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    StrBui.Append("\"");
                    StrBui.Append(dt.Columns[j].ColumnName);
                    StrBui.Append("\":\"");
                    StrBui.Append(dt.Rows[i][j].ToString());
                    if (j == dt.Columns.Count - 1)
                    {
                        StrBui.Append("\"");
                    }
                    else
                    {
                        StrBui.Append("\",");
                    }
                }
                if (i == dt.Rows.Count - 1)
                {
                    StrBui.Append("}");
                }
                else
                {
                    StrBui.Append("},");
                }            }
            StrBui.Append("];");
            str = StrBui.ToString();            Response.Clear();
            Response.Write(StrBui);
            Response.End();
        }
    }
}
求高手帮忙看下是哪不对  只会显示内容读取中...
是我$.getJSON 写法不对,不能传入参数还是无法获取到后台返回的接送数据呢?

解决方案 »

  1.   

      StrBui.Append("];");
      str = StrBui.ToString();  Response.Clear();
      Response.Write(StrBui);
      Response.End();
      }
      }
    }
      

  2.   

    跟我的问题一样 context.Response.Write(Json);
            context.Response.End();你在 写入以后  在 js alert 里面   做 调试 
      

  3.   

    [{"ID":"66","showTitle":"客栈环境5","showImg":"2011031912044375000.jpg"}];
    这是我读出来的数据 格式应该对了吧?不对的话该怎么写呢?求求各位老大帮帮忙啊 偌大一个CSDN 高手如云 难道就没人能救救小弟?!
      

  4.   

    标准的
    懒的写了 周末写个DEMO
      

  5.   

    解决了 几乎没怎么改 只是把$.getJSON换成了$.post  但还是百思不得其解啊...期待子夜周末的DEMO  好好学习下