日期:2014-05-19  浏览次数:20449 次

请教javascript调用服务器方法的问题
我用ajax写聊天室,其中javascript调用了服务器方法是这样的
<script   language= "javascript ">
    //发送消息
    function   send()
    {
      var   txtContent   =   document.all( "content ").value;   //文本框输入内容
      if   (txtContent   ==   " ")   return;
     
      var   user_to   =   document.all( "userlist ").value;     //聊天对象
      var   textcolor   =   document.all( "textcolor ").value;     //颜色
      var   expression   =   document.all( "expression ").value;     //表情
      var   isPublic   =   !(document.all( "isSecret ").checked);     //是否密谈        
     
      //调用服务器端方法发送消息
      Chat.ChatRoom.SendMsg(txtContent,   user_to,   textcolor,   expression,   isPublic);
     
      //更新聊天内容显示
      var   div   =   document.all( "chatcontent ");
      div.innerHTML   =   Chat.ChatRoom.GetNewMsgString().value   +   div.innerHTML;
     
      //清空输入框
      document.all( "content ").value   =   " ";
    }
其中SendMsg()是cs文件里写的方法,项目叫“Chat”,方法所在页面是“ChatRoom”为什么我每次登录进去都报Chat为定义
请求帮忙,我的分也不错了,现在也不涨可用分了,只有差不多那么多了。请帮忙看一下,谢谢大家

------解决方案--------------------
用ajax.pro,在web.config和CS文件中都要写些什么..


你写了没?如果没有写的话,是不行的.

再次,他的调用方式是 类名.方法名
------解决方案--------------------
应该是没注册后台调用方法
------解决方案--------------------

AjaxPro.Utility.RegisterTypeForAjax(typeof(ChatRoom ));
------解决方案--------------------
再帮你顶一下
------解决方案--------------------
刚好在李天平的BOLG上看了一点
http://www.cnblogs.com/ltp/archive/2005/12/03/289725.html
------解决方案--------------------
[AjaxMethod]
public XXXXX GetNewMsgString()
{

}
------解决方案--------------------
其他的都做了后,最后检查是不是没有 <form runat=server id= "form1 "> </form>
------解决方案--------------------
下载个ajaxpro6.5.9.1,并引用试下。
1.Web.config里
<system.web>

<httpHandlers>
<add verb= "* " path= "ajaxpro/*.ashx " type= "AjaxPro.AjaxHandlerFactory,AjaxPro "/>
</httpHandlers>
</system.web>

2.页面加载事件里
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
AjaxPro.Utility.RegisterTypeForAjax(typeof(类名));
}

3.在服务器端方法上边加ajax标记
[AjaxPro.AjaxMethod]
public string xxxxx()
{
xxxxxxxx;
}
4.javascript调用
<script>
命名空间.类名.方法名()
</script>

基本就是这样,看看能对lz有什么帮助。
------解决方案--------------------
delete all ajax method in your cs file and compile your class, if no error happen and then add the ajax method compile again,just try it