简体   繁体   English

Ajax 成功事件不触发

[英]Ajax success event doesn't fire

Doing Okta Authentication on WebForms The login works but the redirect part doesnt在 WebForms 上进行 Okta 身份验证登录有效,但重定向部分无效

I tried with void and to return json object/string but doenst work我尝试使用 void 并返回 json 对象/字符串,但确实有效

if i delete contentType and dataType from ajax method the success event works but then i can't debbug the method and it wasn't doing what was suppose to do如果我从 ajax 方法中删除 contentType 和 dataType ,则成功事件有效,但是我无法调试该方法,并且它没有做应该做的事情

My objective is at the end of the webmethod to redirect to SignedIn.aspx tried with this code but couldn't make it work either that's why im doing client side through ajax success method我的目标是在 webmethod 的末尾重定向到 SignedIn.aspx 尝试使用此代码但无法使其工作,这就是为什么我通过 ajax 成功方法做客户端的原因

     HttpContext.Current.Response.Redirect("SignedIn.aspx");

Ajax: Ajax:

function FormSubmit() {
    $.ajax({
        type: "POST",
        url: "Example.aspx/Login",
        data: "{hiddenSessionTokenField:'" + $('#hiddenSessionTokenField').val() + "'}",
        dataType: "json",
        async:false,
        contentType: "application/json; charset=utf-8",
        success: function (response) {
            alert("Method Called Sucessfully" + response);
            window.location.href = "http://localhost:8080/SignedIn.aspx";
        },
        error: function (response) {
            alert("error " + response);
        }
    });
}

WebMethod网络方法

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static void Login(string hiddenSessionTokenField)
        {

        //var result = new { url = "http://localhost:8080/SignedIn.aspx" };

        if (!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            var properties = new AuthenticationProperties();
            properties.Dictionary.Add("sessionToken", hiddenSessionTokenField);
            properties.RedirectUri = "~/SignedIn.aspx";

            //Okta Authentication
            HttpContext.Current.GetOwinContext().Authentication.Challenge(properties,
                OpenIdConnectAuthenticationDefaults.AuthenticationType);


            //System.Web.Script.Serialization.JavaScriptSerializer s = new System.Web.Script.Serialization.JavaScriptSerializer();

            //return s.Serialize(result));

        }
            //return s.Serialize(result));

    }
$('#test').on('click', function () {
    $.ajax({
      type: "POST",
      url: "TEST.aspx/Login",
      data: "{hiddenSessionTokenField:'" + $('#hiddenSessionTokenField').val() + "'}",
      dataType: "json",
      contentType: "application/json; charset=utf-8",
      success: function (response) {
    //    alert("Method Called Sucessfully");
      window.location.href = "http://localhost:8080/index.aspx";
   },
    error: function (response) {
      alert("error " + response);
       }
      });
     })


    public static void Login(string hiddenSessionTokenField) {
        int x = 0;

    }

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

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