Home » Jquery » javascript – how to get service response and toggle modalpop with asp.net 4.0-Exceptionshub

javascript – how to get service response and toggle modalpop with asp.net 4.0-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

i have one eb service that send otp with cheking some condition from database. here is my code of service :

[WebMethod]
    [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
    public string SendOTP(string username)
    {
        string Response = string.Empty;
        try
        {
            bool _isOTP = false;
            LoginRequest login = new LoginRequest();
            login.UserName = SiteUser.Current().UserName.ToString();
            login.Password =  SiteUser.Current().Password.ToString();

            LoginLibrary.Business.SMSUser.VLUser objUser = SiteUser.AuthenticateUser(login);

            if (objUser != null)
            {
                _isOTP = objUser.isOTP;
                if (_isOTP == true)
                {
                    SiteUser.GenerateUserAuthentication(username);
                    Response = "Success";
                }
                else
                {
                    Response = "NoOTP";
                }
            }
        }
        catch (Exception ex)
        {
            Response = "Error in Sending OTP to : " + username + CommonMethods.GetErrorMessage(ex, "OTPSend");
        }
    RESPONSE:
        if (!string.IsNullOrWhiteSpace(Response))
            AppGlobal.Logger.WriteToErrorLogFile(Response);
        return Response;
    } 

with it response i just make y modal popup hide or show :

 function SendOTP() {

            $.ajax({
                url: "../Service/UserManage.asmx/SendOTP",
                type: "POST",
                dataType: "json",
                data: '{username:"' + $('#<%=hfusername.ClientID %>').val()  +'" }',
                contentType: "application/json; charset=utf-8",
                async: false,
                success: function(response)
                {
                    if( response == 'NoOTP')
                        $('#myModalOTP').modal('hide')
                    else 
                        $('#myModalOTP').modal('show')
                },
                failure: function (response) {
                    toastr["error"](response.d, "FAIL");
                },
                error: function (response) {
                    toastr["error"](response.d, "ERROR");
                }
            });
        }

but my modal popup always show…………….. whats going wrong here please help me………………

How to&Answer: