<script type= "text/javascript" language= "javascript" > |
$( function () { |
//同步问题信息 |
$( "#comemnt_list" ).ready( function () { |
startRequest(); |
setInterval( "startRequest()" , 5000); |
}); |
}); |
//获取聊天信息 |
function startRequest() { |
var STDBXID = getArgs( "AutoID" ); |
$.ajax({ |
type: "POST" , |
url: "STDBZMainTalkShow.ashx" , |
dateType: "json" , |
data: { STDBXID: STDBXID }, |
success: function (returnedData) { |
if (returnedData) { |
var result = eval( '(' + returnedData + ')' ); |
var Total = result.Total; |
$( "#comemnt_list" ).html(Total); |
} else { |
$( "#comemnt_list" ).html( "获取聊天信息出错" ); |
} |
} |
}); |
} |
//输入聊天信息 |
function TalkInsert() { |
STDBXID = getArgs( "AutoID" ); |
var Message = $.trim($( "#comment_content" ).val()); |
var User = $.trim($( "#ContentPlaceHolder_UserID" ).val()); |
var ENTID = $.trim($( "#ContentPlaceHolder_ENTID" ).val()); |
if (Message == "" || Message == null ) { |
alert( "内容不能为空" ) |
} |
else { |
$.ajax({ |
type: "POST" , |
url: "STDBZMainTalkInsert.ashx" , |
dateType: "json" , |
data: { Message: Message, User: User, STDBXID: STDBXID, ENTID: ENTID }, |
success: function (returnedData) { |
if (returnedData) { |
$( "#comment_content" ).val( '' ); |
startRequest(); |
} else { |
$( "#comment_content" ).val( '系统异常' ); |
} |
} |
}); |
} |
} |
//获取query string |
function getArgs(strParame) { |
var args = new Object(); |
var query = location.search.substring(1); // Get query string |
var pairs = query.split( "&" ); // Break at ampersand |
for ( var i = 0; i < pairs.length; i++) { |
var pos = pairs[i].indexOf( '=' ); // Look for "name=value" |
if (pos == -1) continue ; // If not found, skip |
var argname = pairs[i].substring(0, pos); // Extract the name |
var value = pairs[i].substring(pos + 1); // Extract the value |
value = decodeURIComponent(value); // Decode it, if needed |
args[argname] = value; // Store as a property |
} |
return args[strParame]; // Return the object |
} |
</script> |
=================================================show.ashx |
<%@ WebHandler Language= "C#" Class= "Handler" %> |
using System; |
using System.Web; |
using System.Data; |
using System.Configuration; |
using entsut.DAL; |
public class Handler : IHttpHandler |
{ |
public void ProcessRequest(HttpContext context) |
{ |
string json = "" ; |
string STDBXID = context.Request[ "STDBXID" ].ToString(); |
try |
{ |
DataSet ds = Common.NoPager2( "Std_BZQqustions" , "10" , "ID,QuestionDes,createTime,createUser,createUser_entID" , "createTime Desc" , "STDBXID='" + STDBXID + "' and Valided=1" ); |
DataTable dt = ds.Tables[0]; |
int i = dt.Rows.Count; |
string[] talk = new string[i]; |
string Total = null ; |
for (int j = 0; j <= i - 1; j++) |
{ |
talk[j] = "<li class=\"comment_list\" style=\"font-size: 12px;\"><span class=\"creator\">" + dt.Rows[j][ "createUser" ] + "<a class=\"talktime\">(" + dt.Rows[j][ "createTime" ] + ")</a></span>:<p class=\"talk\">" + dt.Rows[j][ "QuestionDes" ] + "</p></li>" ; |
Total = Total + talk[j]; |
} |
json = "{'Total':'" + Total + "'}" ; |
context.Response.Write(json); |
} |
catch |
{ |
context.Response.Write(json); |
} |
} |
public bool IsReusable |
{ |
get |
{ |
return false ; |
} |
} |
} |
===================================insert |
<%@ WebHandler Language= "C#" Class= "Handler" %> |
using System; |
using System.Web; |
using System.Data; |
using System.Configuration; |
using entsut.DAL; |
using entsut.Core; |
using System.Text.RegularExpressions; |
public class Handler : IHttpHandler |
{ |
public void ProcessRequest(HttpContext context) |
{ |
string json = "" ; |
string STDBXID = context.Request[ "STDBXID" ].ToString(); |
string Message = context.Request[ "Message" ].ToString(); |
string UserID = context.Request[ "User" ].ToString(); |
string ENTID = context.Request[ "ENTID" ].ToString(); |
try |
{ |
string Notice = Common.Insert2( "Std_BZQqustions" , "QuestionDes,createTime,createUser,createUser_entID,Valided,STDBXID" , "'" + Message + "','" + DateTime.Now + "','" + UserID + "','" + ENTID + "',1,'" + STDBXID + "'" ); |
json = "{'Notice':'" + Notice + "'}" ; |
context.Response.Write(json); |
} |
catch |
{ |
context.Response.Write(json); |
} |
} |
public bool IsReusable |
{ |
get |
{ |
return false ; |
} |
} |
} |