简体   繁体   English

jQuery AJAX发布到asp.net webmethod永远不会被调用?

[英]JQuery AJAX post to asp.net webmethod never getting called?

I am trying to send data from my javascript to an aspx webmethod with ajax. 我正在尝试将数据从我的JavaScript发送到使用Ajax的aspx webmethod。 the Success option of ajax post is fired but my web method never getting called. ajax post的Success选项被触发,但是我的Web方法从未被调用。 the javascript code is: javascript代码是:

 $.ajax({
    type: "POST",
    url: '../About.aspx/GetWFData',
    data: "{sendData: '" + 5 + "'}",
    async: true,
    success: function (result) {
        alert("Bravo");
    },
    error: function (jqXHR, textStatus, errorThrown) {
        alert(textStatus);
        alert(errorThrown);
    }
});

and the webmethod in the code behind is: 而后面代码中的web方法是:

 [WebMethod]
    public static string GetWFData(string sendData)
    {
        return String.Format("Hello");
    }

Try to use below code to see if it works. 尝试使用下面的代码查看它是否有效。

var params = '{sendData:' + values + '}';
 $.ajax({
    type: "POST",
    url: '../About.aspx/GetWFData',
    data: JSON.stringify(params),
    async: true,
    success: function (result) {
        alert("Bravo");
    },
    error: function (jqXHR, textStatus, errorThrown) {
        alert(textStatus);
        alert(errorThrown);
    }
});

And refer to http://elegantcode.com/2009/02/21/javascript-arrays-via-jquery-ajax-to-an-aspnet-webmethod/ for more info. 并参阅http://elegantcode.com/2009/02/21/javascript-arrays-via-jquery-ajax-to-an-aspnet-webmethod/了解更多信息。 Try to disable request validation on a page. 尝试禁用页面上的请求验证。 http://www.asp.net/whitepapers/request-validation http://www.asp.net/whitepapers/request-validation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM