jQuery AJAX Error: Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Last Reply 6 months ago By dharmendr

Posted 6 months ago

Hello everyone,

I am calling a server side method using jQuery and Ajax but getting an "Failed to load resource: the server responded with a status of 500 (Internal Server Error)". I am unable to figure it out kindly, help me correcting out.

Any suggestions will be appriciated below is my code.

    <script src="../bootstrap/jQuery/jquery-3.3.1.js" type="text/javascript"></script>
    <script src="../bootstrap/jQuery/jquery-ui.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnSubmit').click(function () {
                $.ajax({
                    url: 'RTGS_FileUpload.aspx/send',
                    method: 'post',
                    contentType: 'application/json',
                    data: '{}',
                    dataType: "json",
                    success: function (data) {
                        alert(data.d.Session["OTP"]);
                    },
                    error: function (error) {
                        alert('error');
                    }
                });
            });
        });
    </script>

 

        [WebMethod]
        public static void SendOTP()
        {
            RTGSFileUpload rfu = new RTGSFileUpload();
            BELAP getAgencyBel = new BELAP();
            getAgencyBel.ImplementingAgency = Convert.ToInt16(rfu.Session["Agency_Id"]);
            BALAP getContactBal = new BALAP();
            getAgencyBel.ContactNo = getContactBal.getAgencyContactDetails(getAgencyBel).ToString();

            BELSMS objEntity = new BELSMS();
            objEntity.Mobile = "+91" + getAgencyBel.ContactNo;
            if (objEntity.Mobile != null)
            {
                rfu.lblContact.Text = "Please enter OTP Send on XXXXXX" + objEntity.Mobile.Substring(objEntity.Mobile.Length - 4);
                BALSMS objSet = new BALSMS();
                rfu.Session["OTP"] = objSet.SendOtp(objEntity);
            }
            else
            {
                rfu.lblContact.Text = "Please contact system administrator";
            }
        }

 

Posted 6 months ago

Hi AbdulHaque,

Please rectify below points.

1. Your WebMethod name is SendOTP and you are calling as send in jquery.

2. Add below attribute to you WebMethod.

[System.Web.Services.WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]

3. If you want to show message from the response then instead of void type return string type.