Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用处理程序从服务器获取答案_C#_Asp.net_Ajax_Handler - Fatal编程技术网

C# 使用处理程序从服务器获取答案

C# 使用处理程序从服务器获取答案,c#,asp.net,ajax,handler,C#,Asp.net,Ajax,Handler,我正在使用一个处理程序来运行服务器代码,从浏览器中我可以看到服务器的答案,但我无法在我的源代码中得到它 我这样称呼处理者: $.ajax({ type : "json", url : "../Handlers/Handler.ashx?MethodName=ReadAnswerServerID", success : function(data){ alert('insi

我正在使用一个处理程序来运行服务器代码,从浏览器中我可以看到服务器的答案,但我无法在我的源代码中得到它

我这样称呼处理者:

           $.ajax({
            type : "json",
            url : "../Handlers/Handler.ashx?MethodName=ReadAnswerServerID",
            success : function(data){
                alert('inside success');
            }
        });
我可以在成功块中得到答案,但我从来都看不到警报

这是处理程序:

    public void ProcessRequest(HttpContext context)
    {
        string method = context.Request.QueryString["MethodName"].ToString();
        context.Response.ContentType = "application/json";
        switch (method)
        {
            case "ReadAnswerServerID":
                context.Response.Write(ReadID());
                break;
        }
    }
ReadID返回一个字符串值。

我假设“ReadID()”返回有效的JSON,否则可能是您的问题

您可以在ProcessRequest内设置断点,连接到w3wp,并在Javascript调用执行时点击断点


如果没有,您是否检查了web.config中的处理程序注册?

我可以在成功块中得到答案,但我永远看不到警报
如果您没有看到警报,则不会执行成功代码。使用并比较您的代码和浏览器发送的内容…谢谢!这是钥匙!我使用以下命令返回了一个普通的stirng:Newtonsoft.Json.JsonConvert.SerializeObject();我到达成功街区,谢谢你的帮助!!