Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Jquery ajax未在url中调用方法_Jquery_Ajax_Dropdownbox - Fatal编程技术网

Jquery ajax未在url中调用方法

Jquery ajax未在url中调用方法,jquery,ajax,dropdownbox,Jquery,Ajax,Dropdownbox,这是我第一次使用ajax,所以我不确定哪里出了问题。 当下拉列表更改时,我在javascript中调用一个方法,我想在代码隐藏中调用一个方法。 这是下拉列表的标记: <asp:DropDownList ID="ddListSubject" runat="server" ClientIDMode="Static" onchange="SubjectChanged()" CssClass="chosen-single"> </asp:DropDownList

这是我第一次使用ajax,所以我不确定哪里出了问题。 当下拉列表更改时,我在javascript中调用一个方法,我想在代码隐藏中调用一个方法。 这是下拉列表的标记:

    <asp:DropDownList ID="ddListSubject" runat="server" ClientIDMode="Static" onchange="SubjectChanged()" CssClass="chosen-single">
        </asp:DropDownList>
函数“ShowMaxMsgLength”包含用于在代码隐藏中调用方法的ajax代码:

function ShowMaxMsgLength() {                          
        $.ajax({
                type: "POST",
                url: "Default.aspx/GetMaxMsgLength",
                data: "{'id': '1'}",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                success: OnSuccess,
                failure: OnFailure,
                error: function (exception) { alert('Exception:' + exception); }
                });
    };
 public static string GetMaxMsgLength(int id)
        {
            string tstrMaxMsgLength = string.Empty;       
            return tstrMaxMsgLength = "32";
        }
这是代码隐藏中的GetMaxMsgLength方法:

function ShowMaxMsgLength() {                          
        $.ajax({
                type: "POST",
                url: "Default.aspx/GetMaxMsgLength",
                data: "{'id': '1'}",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                success: OnSuccess,
                failure: OnFailure,
                error: function (exception) { alert('Exception:' + exception); }
                });
    };
 public static string GetMaxMsgLength(int id)
        {
            string tstrMaxMsgLength = string.Empty;       
            return tstrMaxMsgLength = "32";
        }
我现在只想让它返回'32',看看它是否正在运行该方法。 我知道showmsglength的名字是因为我在里面放了一个“警报”

返回异常:“异常:[object]”。 我不知道我没有设置什么导致此异常


谢谢。

这是只有新手才会错过的。。。 补充 方法前的[System.Web.Services.WebMethod]属性,GetMaxMgsLength