悬赏园豆:80
[已关闭问题]
<P>帮忙看看下面的程序是什么问题? <BR>帮忙看看下面的程序是什么问题?运行到红色字体的地方就不行了。。</P>
<P>这个是按书上写的,刚刚学AJAX,郁闷啊,,, <BR><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <BR><BR><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <BR><BR><html xmlns="http://www.w3.org/1999/xhtml" > <BR><head runat="server"> <BR><title>无标题页 </title> <BR><script type="text/javascript"> <BR>var xmlHttp; //用于保存XMLHttpRequest对象的全局变量 <BR>var basePath = ""; //图片保存目录 <BR><BR>//用于创建XMLHttpRequest对象 <BR>function createXmlHttp() { <BR>//根据window.XMLHttpRequest对象是否存在使用不同的创建方式 <BR>if (window.XMLHttpRequest) { <BR>xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式 <BR>} else { <BR>xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式 <BR>} <BR>} <BR><BR>//向服务器获取图片信息 <BR>function getPicInfo() { <BR>createXmlHttp(); //创建XMLHttpRequest对象 <BR>xmlHttp.onreadystatechange = displayPreview; //设置回调函数 <BR>xmlHttp.open("GET", "Default2.aspx", true); //发送GET请求 <BR>xmlHttp.send(null); <BR>} <BR><BR>//处理服务器返回信息 <BR>function displayPreview() { <BR>if (xmlHttp.readyState == 4) { <BR>var previewDiv = document.getElementById("previewDiv"); //获取预览图容器对象 <BR>previewDiv.innerHTML = ""; //清空容器内容 <BR><BR><FONT color=#ff0000>var pics = eval("(" + xmlHttp.responseText + ")"); //将服务器信息转为JSON数组 <BR>alert("1");这里没有弹出"1" 怎么转化成JOSN数组啊? //遍历整个JSON数组,创建预览图片</FONT> <BR>for (var i=0; i <pics.length; i++) { <BR>var pic = pics; <BR>previewDiv.appendChild(createPreviewPic(pic)); //在容器内追加预览图节点 <BR>} <BR>} <BR>} <BR><BR>//创建预览图片节点 <BR>function createPreviewPic(pic) { <BR>var picNode = document.createElement("div"); <BR>picNode.className = "preview"; <BR>picNode.innerHTML = " <img src='"+ pic.url + "' onclick='loadPic( '"+ pic.url +"' )'>"; <BR>return picNode; <BR>} <BR><BR>//加载完整图片 <BR>function loadPic(picName) { <BR>document.getElementById("picDiv").innerHTML = " <img src='"+ picName + "'>"; <BR>} <BR></script> <BR></head> <BR><body > <BR><form id="form1" runat="server"> <BR><div> <BR><h1>相册浏览 </h1> <BR><BR><table class="default"> <BR><tr> <BR><td class="item">点击缩略图查看完整图片 </td> <BR></tr> <BR><tr> <BR><td> <BR><div id="previewDiv">正在加载缩略图…… </div> <BR></td> <BR></tr> <BR><tr> <BR><td> <BR><div id="picDiv"> </div> <BR></td> <BR></tr> <BR></table> <BR><BR></div> <BR></form> <BR></body> <BR></html> <BR>Default2.aspx.cs <BR>这里是没有错误的,我运行过了 <BR><BR>StringBuilder picInfo = new StringBuilder("["); <BR>int count = 0; <BR>string cmdtext = "select * from url where url"; <BR>OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("db.mdb")); <BR>conn.Open(); <BR>OleDbCommand cmd = new OleDbCommand(cmdtext, conn); <BR>OleDbDataReader rs = cmd.ExecuteReader(); <BR>while (rs.Read ()) <BR>{ <BR>if (count > 0) <BR>{ <BR>picInfo.Append(","); <BR>} <BR>picInfo.Append("{"); <BR>picInfo.Append("'leixing':'"); <BR>picInfo.Append(rs.GetString (1)); <BR>picInfo.Append("','surl':'"); <BR>picInfo.Append(rs.GetString(2)); <BR>picInfo.Append("','url':'"); <BR>picInfo.Append(rs.GetString(3)); <BR>picInfo.Append("}"); <BR>count++; <BR>} <BR>rs.Close(); <BR>conn.Close(); <BR>picInfo.Append("]"); <BR>Response .Write (picInfo .ToString ()); <BR><BR><BR>} <BR>将服务器信息(xmlHttp.responseText )转为JSON数组 <BR>怎么转啊/</P>
问题补充:
picInfo.Append("}"); 这个错了picInfo.Append("'}");,该成这样还是不行啊!!
less
|
初学一级
|
园豆:
120
提问于:2008-08-21 20:20