<%@ 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 写法不对,不能传入参数还是无法获取到后台返回的接送数据呢?
<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 写法不对,不能传入参数还是无法获取到后台返回的接送数据呢?
解决方案 »
- 一般模板template.cs里都要实现哪些功能?
- 怎么删除gridview中ID = n的记录,只在gridview中删除
- 在SessionParameter中如何传递当前用户的id?
- 看了很我搜索里的相关内容,没有这块,系统自定义的DropDownList默认值,
- 一段看不懂的javascript的代码!(开发java的高手帮帮忙呀!)
- asp.net网站服务端接口问题?
- 新革命:我用DataSet插入一行记录,怎样把刚插入的记录写入到Xml文件中。
- DataGrid控件有合计功能吗?如有?怎用?
- QQ交谈问题?
- 服务器端控件太难用。。
- asp.net 怎样将一串用空格隔开的标签字符分离出来
- asp.net 没有权限访问数据库
str = StrBui.ToString(); Response.Clear();
Response.Write(StrBui);
Response.End();
}
}
}
context.Response.End();你在 写入以后 在 js alert 里面 做 调试
这是我读出来的数据 格式应该对了吧?不对的话该怎么写呢?求求各位老大帮帮忙啊 偌大一个CSDN 高手如云 难道就没人能救救小弟?!
懒的写了 周末写个DEMO