Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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# 执行jquery-ajax-c success函数,但没有响应_C#_Jquery - Fatal编程技术网

C# 执行jquery-ajax-c success函数,但没有响应

C# 执行jquery-ajax-c success函数,但没有响应,c#,jquery,C#,Jquery,帖子被解雇了,我可以在firebug中看到下面的内容 POST http://localhost:1148/WebSite2/frmMain.aspx/webDelete 200 OK 15ms jQuery代码是: 然后,成功函数中会触发两个警报,但第二个警报为空 服务器端编码: 目前在没有param参与的情况下尝试,错误函数为triggeres,没有成功 jquery代码 服务器代码 firebug信息: 响应头 请求头 为了看看出了什么问题 调试webDelete以查看id实际上是“ab

帖子被解雇了,我可以在firebug中看到下面的内容

POST http://localhost:1148/WebSite2/frmMain.aspx/webDelete 200 OK 15ms
jQuery代码是:

然后,成功函数中会触发两个警报,但第二个警报为空

服务器端编码:

目前在没有param参与的情况下尝试,错误函数为triggeres,没有成功

jquery代码

服务器代码

firebug信息:

响应头

请求头


为了看看出了什么问题

调试webDelete以查看id实际上是“abc”! 解析表单数据时可能出现问题

使用FireBug或Chrome F12检查实际响应

尝试导航到:

http://localhost:1148/WebSite2/frmMain.aspx/webDelete?id=myNeetID
这会激发WebMethod吗? 返回myNeetID还是空白?
注意:您可能需要启用GET方法。

如果结合使用[WebMethod][ScriptMethod],则需要对ajax调用进行一些更改

$.ajax({
   url: "frmMain.aspx/webDelete",
   type: "POST",  
   dataType: "json",
   contentType: "application/json; charset=utf-8",
   data: JSON.stringify({id:"abc"}),
   success: function(data){alert("success");alert(data.d)},
   error: function(){alert("failed");}
});
见:


谢谢大家的帮助^_^

我通过这篇精彩的帖子找到了答案


注意:此isuue是由.NET版本问题引起的

1。该代码无法执行2。实际响应是客户端第3页的html代码。如何在此评论中添加新行!?什么也没发生,我在firebug中没有看到任何ajax帖子,所以没有请求,没有响应,只要我点击那个url页面就会加载。@rps它只是为了测试。某些配置不允许GET请求。我会让你知道后,给一个尝试,但为什么JSON?因为“ScriptMethod”告诉服务器方法请求是通过脚本触发的?起初我没有包括“ScriptMethod”,当时它也不起作用;将$.toJSON更改为JSON.stringify,因为出现错误“$.toJSON不是函数”,我还从服务器端删除了内容类型。失败的警报使firedAh正常。很抱歉,toJSON不是标准JQuery的一部分。从服务器端删除数据类型也可以。你能调试与Firebug的通信吗?这将使我们更好地了解请求的进展情况。http://localhost:1148/WebSite2/frmMain.aspx/webDelete 这就是firebug中的请求链接,我想它缺少参数了吧?数据:{id:abc}这就是我在JQuery代码中给出参数的方式,在firebug的post视图中,我看到Source id=abc。数据应该是post消息的一部分。您没有看到任何参数作为URL的一部分,因为您正在执行POST。源代码应作为JSON发送。不像通常那样作为键/值集合
$.ajax({

        url: "frmMain.aspx/webDelete",
        type: "POST",  
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: "{}",
        async: true,            
        success: function(data){alert("success");alert(data.d) },
        error: function(){alert("failed"); }

    } );
[WebMethod][ScriptMethod]
public static string webDelete()
{
   return "hello";
}
Cache-Control   private
Connection          Close
Content-Length  11732
Content-Type    text/html; charset=utf-8
Date            Thu, 18 Jul 2013 09:47:34 GMT
Server          ASP.NET Development Server/8.0.0.0
X-AspNet-Version    2.0.50727
Accept          application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length  2
Content-Type    application/json; charset=utf-8
Host            localhost:1148
Referer         http://localhost:1148/WebSite2/frmMain.aspx
User-Agent          Mozilla/5.0 (Windows NT 5.2; rv:22.0) Gecko/20100101 Firefox/22.0
X-Requested-With    XMLHttpRequest
http://localhost:1148/WebSite2/frmMain.aspx/webDelete?id=myNeetID
$.ajax({
   url: "frmMain.aspx/webDelete",
   type: "POST",  
   dataType: "json",
   contentType: "application/json; charset=utf-8",
   data: JSON.stringify({id:"abc"}),
   success: function(data){alert("success");alert(data.d)},
   error: function(){alert("failed");}
});