使用PageMethods从Javascript调用C#代码隐藏不会';行不通

使用PageMethods从Javascript调用C#代码隐藏不会';行不通,javascript,c#,asp.net,webmethod,pagemethods,Javascript,C#,Asp.net,Webmethod,Pagemethods,我正在尝试使用PageMethods从“Enter key press”上的javascript调用我的C#Web方法 ASP: 代码隐藏: [WebMethod] public string SendChat(string input) { return "Hey there"; } 基本上是尝试从文本框中获取输入文本,将其发送到代码隐藏中的方法,并提醒响应。我基本上得到了一个空警报。我做错了什么?我不太熟悉,但从快速阅读中可以看到,它在后台执行异步AJAX调用时立即返回。您必须

我正在尝试使用PageMethods从“Enter key press”上的javascript调用我的C#Web方法

ASP:

代码隐藏:

[WebMethod]
public string SendChat(string input)
{
      return "Hey there";
}
基本上是尝试从文本框中获取输入文本,将其发送到代码隐藏中的方法,并提醒响应。我基本上得到了一个空警报。我做错了什么?

我不太熟悉,但从快速阅读中可以看到,它在后台执行异步AJAX调用时立即返回。您必须为成功和错误提供回调。成功处理程序应该显示结果

function aichatreply() {
    var inputtext = document.getElementById("new-chat-text-input");
    var x = event.keyCode;
    if (x == 13) {
        alert("The process came here"); //Gets triggered successfully
        PageMethods.SendChat(inputtext, onSuccess, onFailure);
        //This line will execute immediately, not waiting for SendChat to finish
    }
}

function onSuccess(result) {
    alert(result);
}

function onFailure(result) {
    alert("Failed!");
}

相关:@mason这个问题说明了这个网站已经变成了什么样子。每个人都会很快否决他们不理解的内容。@etrem叹气,他们甚至不再试图澄清问题。@etrem你在说什么?这与问题无关,对一个问题投反对票并不意味着什么。最后,你为什么要把你的评论指向我?这个工作伙伴!谢谢酷,太糟糕了,这个问题已经结束了!我不认为有人真的读得很仔细。真的!人们太快了,无法继续前进,哈哈。谢谢你,伙计!
[WebMethod]
public string SendChat(string input)
{
      return "Hey there";
}
function aichatreply() {
    var inputtext = document.getElementById("new-chat-text-input");
    var x = event.keyCode;
    if (x == 13) {
        alert("The process came here"); //Gets triggered successfully
        PageMethods.SendChat(inputtext, onSuccess, onFailure);
        //This line will execute immediately, not waiting for SendChat to finish
    }
}

function onSuccess(result) {
    alert(result);
}

function onFailure(result) {
    alert("Failed!");
}