大家帮我看一下这一点ASP。NET和AJAX代码有什么问题。。。为什么老是不行呢...
这是JAVASCRIPT代码的部分:function getChat()
{
if(document.getElementById("chatmain"))
{
loadXML("GET","getChat.aspx?frompage="+frompage+"&nc="+nc,getChatOK);
}
objTimerout=window.setTimeout("getChat()",1000);
}
function getChatOK(xmlDom)
{
if(document.getElementById("chatmain"))
{
document.getElementById("chatmain").innerHTML="aaa";
document.getElementById("chatmain").innerHTML=xmlDom.responseText;
}
}
chatmain是一个DIV
这个是getChat.aspx页面的逻辑代码:
SqlConnection conC;
private void openConn()
{
string str = ConfigurationManager.ConnectionStrings["xkb_ChatConn"].ConnectionString;
conC = new SqlConnection(str);
conC.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
string TempStr = "";
string Url = Request["frompage"];
string sqlStr = "select * from Chat_room where fromPage='"+Url+"' and datediff(ss,'" +dt+ "',dateandtime)>0 order by id desc";
openConn();
SqlCommand cmd = new SqlCommand(sqlStr,conC);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TempStr = ds.Tables[0].Rows[i]["nickName"].ToString() + ":" + ds.Tables[0].Rows[i]["chatMsg"].ToString() + "[" + DateTime.Parse(ds.Tables[0].Rows[i]["dateandtime"].ToString()).ToShortDateString() + "]\n";
Response.Write(TempStr);
}
conC.Close();
}
为什么它不能把数据库中的东西取出来放到那个chatmain的DIV中去呢。。。谢谢. --------------------编程问答-------------------- protected void Page_Load(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
string TempStr = "";
string Url = Request["frompage"];
string sqlStr = "select * from Chat_room where fromPage='"+Url+"' and datediff(ss,'" +dt+ "',dateandtime)> 0 order by id desc";
openConn();
SqlCommand cmd = new SqlCommand(sqlStr,conC);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TempStr += ds.Tables[0].Rows[i]["nickName"].ToString() + ":" + ds.Tables[0].Rows[i]["chatMsg"].ToString() + "[" + DateTime.Parse(ds.Tables[0].Rows[i]["dateandtime"].ToString()).ToShortDateString() + "]\n";
Response.Write(TempStr);
}
conC.Close();
}
function ajaxSubmit(){
var xmlHttp;
try{
xmlHttp = new XMLHttpRequest();
}
catch(e){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//创建请求处理结果程序
xmlHttp.onreadyStatechange = function(){
if(4 == xmlHttp.readyState){
if(200 == xmlHttp.Status){
document.getElementById("chatmain").innerHTML=xmlDom.responseText;
}
else{
alert("失败");
}
}
}
xmlHttp.open("GET",true);
//post时才设的HTTP头
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlHttp.send("getChat.aspx?frompage="+frompage+"&nc="+nc,getChatOK)
} --------------------编程问答-------------------- -_-!
到底用ajax.net 还是XMLHTTP
技术选型不要东摆西摆 --------------------编程问答-------------------- 自己在浏览器输入
getChat.aspx?frompageyy&nc=xx
(上面的参数我随手敲的,你要输入个可以取到值的参数)
然后看页面有没有正确的输出.
如果没有检查你cs代码, 如果有,那么检查你js, 可以逐行加入 alert("xx") 来调试. --------------------编程问答-------------------- 二楼的朋友..请指点一下..我就是前后用的XMLHTTP与ASP.NET代码交互...ASP.NET页面负责处理数据...
不太明白您的意思,谢谢.请指点... --------------------编程问答-------------------- function getChat()
{
if(document.getElementById("chatmain"))
{
loadXML("GET","getChat.aspx?frompage="+frompage+"&nc="+nc,getChatOK);
}
objTimerout=window.setTimeout("getChat()",1000);
}
nc和 frompage根本没有定义么!
定期刷新简单点的下载一个asp.net ajax吧里面有一个timer控件
补充:.NET技术 , ASP.NET