[求助]对象不支持此属性或方法~~
聊天室显示在线列表:
前台JS代码:
function GetOnlineUsers()
{
var userlist=ChatRoom.GetOnLineUsers().value;//对象不支持此属性或方法
var userArr = userlist.split( ', ');
var tableHTML = " <table> ";
for (var i = 0;i < userArr.length;i++)
{
tableHTML += " <tr> <td> <label onmouseover=\ "this.style.cursor= 'hand '\ " onmouseout=\ "this.style.cursor= 'default '\ " onclick=\ "setObj( ' " + userArr[i] + " ')\ "> " + userArr[i] + " </label> <br> </td> </tr> ";
}
tableHTML += " </table> ";
var div = document.all( "onlineuser ");
div.innerHTML = tableHTML;
}
在注释行即为报的错~~
后台CS代码:
[Ajax.AjaxMethod()]
public string GetOnlineUsers()
{
string aaa=@ "Data Source=localhost;user ID=sa;password=111;initial catalog=MyChatRoom ";
SqlConnection strconn=new SqlConnection(aaa);
SqlCommand cmd = strconn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetOnlineUsers ";
string mm= " ";
strconn.Open();
SqlDataReader ss=cmd.ExecuteReader();
if(ss.Read())
{
mm+=ss.GetString(1)+ ", ";
}
strconn.Close();
return mm.TrimEnd( ', ');
}
[解决办法]
1、在web.config文件裡添加如下語句:
<httpHandlers>
<add verb= "* " path= "*.ashx " type= "AjaxPro.AjaxHandlerFactory,AjaxPro.2 "/>
</httpHandlers>
2、添加引用,並在CS文件的page_load裡引用:
AjaxPro.Utility.RegisterTypeForAjax(typeof(類名));
3.调用的aspx页面必须要有forme runat= "server "