Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
Javascript 对webmethod的ajax调用不';在asp.net中不成功_Javascript_Asp.net_Ajax - Fatal编程技术网

Javascript 对webmethod的ajax调用不';在asp.net中不成功

Javascript 对webmethod的ajax调用不';在asp.net中不成功,javascript,asp.net,ajax,Javascript,Asp.net,Ajax,我在页面say Test.aspx中有一个ajax请求 $.ajax({ type: "POST", url: "Test.aspx/TestMethod", data: "{ 'Parameter':'Parameter'}", contentType: "application/json; charset=utf-8", data

我在页面say Test.aspx中有一个ajax请求

  $.ajax({
                type: "POST",
                url: "Test.aspx/TestMethod",
                data: "{ 'Parameter':'Parameter'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (res) {
                    alert('success');
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert('error getting Regions');
                }
            });
在代码背后

   [WebMethod()]
    public static string TestMethod(string Parameter)
    {
      return "teststring";
    }
问题是,在ajax内部,控制无法取得成功,有什么想法吗?“”

test试试这个

$.ajax({
                type: "POST",
                url: "Test.aspx/TestMethod",
                data: "{ 'Parameter':'Parameter'}",
                contentType: "application/json; charset=utf-8",
                success: function (res) {

                    var s = JSON.stringify(res);
                    alert(s);
                },
                error: function () {
                    alert('error getting Regions');
                }
            });

有几件事你需要确保你正在做

首先需要添加脚本管理器,使其具有如下所示的enable page method属性true

<asp:ScriptManager ID="scriptManager" runat="server" EnablePageMethods="true">
</asp:ScriptManager>

检查页面URL和所有内容。它应该是正确的,并且应该与页面名和方法名完全相同,因为它区分大小写

同时检查参数。下面还有一篇关于参数的好帖子,供大家参考


没有。。。更新了我的问题我们不允许在此页面中使用asp控件获取错误0x800a139e-JavaScript运行时错误:asp.NET Ajax客户端框架无法加载查看以下链接-