使用AJAX做无刷新聊天室...
通过页面输入内容发送信息到后台
进行数据库数据插入操作.. [AjaxPro.AjaxMethod()]
public void SendMsg(string id,string submit,string type1,string con,string title,string op,string username)
{
BLL.wwwi_online_aws bll = new BLL.wwwi_online_aws();
Model.wwwi_online_aws model = new Model.wwwi_online_aws();
if (!string.IsNullOrEmpty(id))
{
model = bll.GetModel(int.Parse(id));
}
model.posttime = DateTime.Now;
model.type1 = type1;
if (submit == "继续发表")
{
if (op != "close")
{
model.con = model.con + Environment.NewLine + "-------" + username + "回复(" + DateTime.Now + ")-------" + Environment.NewLine + con + Environment.NewLine;
model.status = "待回复";
}
else
{
model.status = "已结束";
}
bll.Update(model);
}
else
{
model.username = username;
model.status = "新问题";
model.title = title;
model.con = con;
model.agent1 = "n";
bll.Add(model);
}
}
然后再把它读出来 [AjaxPro.AjaxMethod()]
public string GetNewMsgString(string id,string submit,string username)
{
BLL.wwwi_online_aws bll = new BLL.wwwi_online_aws();
Model.wwwi_online_aws model;
if (submit == "继续发表" && id != "")
{
string sql ="username='"+username +"' and id = "+id+"";
DataSet ds = bll.GetDataSet(null, sql, null);
DataView dv = ds.Tables[0].DefaultView;
if (dv.Count <= 0)
{
Common.MessageBox.ShowAndRedirect(Page, "没有找你要继续发表的ID! ", "aws.aspx");
}
} if (!string.IsNullOrEmpty(id))
model = bll.GetModel(int.Parse(id));
else
model = null; if (model != null)
{
string returnStr = string.Format("{0}", model.con.ToString());
return returnStr;
}
else
{
return "";
}
}结果发现回车换行符根本不起作用..
后来把Environment.newline换成
"<br>"结果却提示未知的运行时错误...
请问如何进行回车换行在JAVASCRIPT中...
通过页面输入内容发送信息到后台
进行数据库数据插入操作.. [AjaxPro.AjaxMethod()]
public void SendMsg(string id,string submit,string type1,string con,string title,string op,string username)
{
BLL.wwwi_online_aws bll = new BLL.wwwi_online_aws();
Model.wwwi_online_aws model = new Model.wwwi_online_aws();
if (!string.IsNullOrEmpty(id))
{
model = bll.GetModel(int.Parse(id));
}
model.posttime = DateTime.Now;
model.type1 = type1;
if (submit == "继续发表")
{
if (op != "close")
{
model.con = model.con + Environment.NewLine + "-------" + username + "回复(" + DateTime.Now + ")-------" + Environment.NewLine + con + Environment.NewLine;
model.status = "待回复";
}
else
{
model.status = "已结束";
}
bll.Update(model);
}
else
{
model.username = username;
model.status = "新问题";
model.title = title;
model.con = con;
model.agent1 = "n";
bll.Add(model);
}
}
然后再把它读出来 [AjaxPro.AjaxMethod()]
public string GetNewMsgString(string id,string submit,string username)
{
BLL.wwwi_online_aws bll = new BLL.wwwi_online_aws();
Model.wwwi_online_aws model;
if (submit == "继续发表" && id != "")
{
string sql ="username='"+username +"' and id = "+id+"";
DataSet ds = bll.GetDataSet(null, sql, null);
DataView dv = ds.Tables[0].DefaultView;
if (dv.Count <= 0)
{
Common.MessageBox.ShowAndRedirect(Page, "没有找你要继续发表的ID! ", "aws.aspx");
}
} if (!string.IsNullOrEmpty(id))
model = bll.GetModel(int.Parse(id));
else
model = null; if (model != null)
{
string returnStr = string.Format("{0}", model.con.ToString());
return returnStr;
}
else
{
return "";
}
}结果发现回车换行符根本不起作用..
后来把Environment.newline换成
"<br>"结果却提示未知的运行时错误...
请问如何进行回车换行在JAVASCRIPT中...
解决方案 »
- 求助!jquery datepick日历插件,怎么显示时分秒?可以显示吗?
- js 获得window.open打开的窗口大小
- 请教一个自动计算的问题
- js 语法中input 中 name=id的问题
- [高分]急求popup形式的日历控件,分不够可再加~~~~~~~~~`
- 急啊!在线等!【关于子窗体向父窗体传递值的问题!………………………………………… 】
- 两个问题,有人能回答吗?(我想不太难吧!)
- 怎样让一个窗口一出来就是没有状态栏、菜单栏....
- Javascript 中怎么处理"或者' 问题
- 跪求!!移动端可拖拽div自动吸附边缘
- 从下拉列表中用js取出值,急救呀。。。。。等待中,要分你说话!!
- 求助代码上点一点疑问!请帮忙看看谢谢!!
你这是什么语言呢,我看着向是面向对象的java或者c#
比如如果是java的话直接
println()这样行不?
而是变成了这样
sdfsdf\r\n-------dd回复(2009-6-1 9:38:25)-------\r\nsdfsdf\r\n\r\n-------dd回复(2009-6-1 9:38:29)-------\r\nsdfsdf\r\n
那就可行了,如果要显示成html,再客户端str = str.replace(/\n/g,"<br>");再显示 innerHTML = str;
environment.newline 的作用是和\r\n一样的
这点我试过了...
不行的...
returnStr = returnStr.Replace("\\r\\n","<br>");把"\r\n"替换成"<br>"后,然后
var str=user_aws.GetNewMsgString(id,Submit,username).value;
var strNewMsg = str;运行后发生"未知运行时错误"
是在显示之前替换啊...
后来我又把<br>替换成<br>
这回倒是不出错了..
可显示的却是这样
还是没换行ddddddddddd<br>-------dd回复(2009-6-1 10:21:09)-------\r\njjjjjjjjjjjj\r\n
var str = user_aws.GetNewMsgString(id, Submit, username).value;
str = str.replace("\\r\\n", "<br>");
var str = user_aws.GetNewMsgString(id, Submit, username).value;
str = str.replace("\\r\\n", "<br>");
[AjaxPro.AjaxMethod()]
public string GetNewMsgString(string id,string submit,string username)
{
BLL.wwwi_online_aws bll = new BLL.wwwi_online_aws();
Model.wwwi_online_aws model;
if (submit == "继续发表" && id != "")
{
string sql ="username='"+username +"' and id = "+id+"";
DataSet ds = bll.GetDataSet(null, sql, null);
DataView dv = ds.Tables[0].DefaultView;
if (dv.Count <= 0)
{
Common.MessageBox.ShowAndRedirect(Page, "没有找你要继续发表的ID! ", "aws.aspx");
}
} if (!string.IsNullOrEmpty(id))
model = bll.GetModel(int.Parse(id));
else
model = null; if (model != null)
{
string returnStr = string.Format("{0}", model.con.ToString());
return returnStr;
}
else
{
return "";
}
}