WebMethod not being called

后端 未结 4 1581
-上瘾入骨i
-上瘾入骨i 2020-12-07 02:37

I am passing a javascript variable containing a string to the server via jquery.ajax. Although the \"success\" condition is called, the server-side WebMethod is never calle

相关标签:
4条回答
  • 2020-12-07 02:39

    I have encountered the same issue. After Googling, I found the solution, and it works for me. Navigate to RouteConfig.cs and comment out the line below:

    public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            //settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings);
        }
    }
    
    0 讨论(0)
  • 2020-12-07 02:43

    Try like this: JQuery:

                    var dataString = JSON.stringify({
                        contractName: contractName,
                        contractNumber: contractNumber
                    });
    
                    $.ajax({
                        type: "POST",
                        url: "CreateQuote.aspx/GetCallHistory",
                        data: dataString,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (result) {
                            alert(result);
                                OpenLightBox('divDelete');
    
                        }
                    });
    

    ASPX.CS:

            [System.Web.Services.WebMethod]
            public static string GetCallHistory(string contractName, string contractNumber)
            {
                return "Nalan";
            }
    
    0 讨论(0)
  • 2020-12-07 02:46

    i would want to add one note: you will have data error of your "ID" (or another field) string contains quotes like = '. solve this issue:

    var DTO = {'sendData': ID};
    
                    $.ajax({
                        "type": "POST",
                        "dataType": 'json',
                        "contentType": "application/json; charset=utf-8",
                        "url": sSource,
                        "data": JSON.stringify(DTO),
                        "success": function (msg) {
                            //do something
                        }
                    });
    
    0 讨论(0)
  • 2020-12-07 03:03

    Try following fixes for your Ajax request:

     $.ajax({
                type: "post",
                url: "Playground.aspx/childBind",
                data: "{sendData: '" + ID + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) { alert("successful!" + result.d); }
            })
    

    Notice changed dataType and data value as a string.

    0 讨论(0)
提交回复
热议问题