skip to Main Content

data-orignal-text automatically added in ajax success, Here is my code before

 <button type="submit" disabled class="btn btn-primary btn-lg btn-block loader" id="idBtn">Verify</button>
    $(document).on("submit", "#formVerify", function (e) {
        e.preventDefault(); // avoid to execute the actual submit of the form.
        var form = $(this);
        BtnLoading();
        $.ajax({
            method: 'POST',
            url: form.action,
            data: form.serialize(),
            success: function (response)
            {
                if (response.status == 1) {
                    if(response.user_role == 1) {
                        window.location.href = globalSiteUrl + "/admin/dashboard";
                    }else if(response.user_role == 3){
                        window.location.href = globalSiteUrl + "/admin/user_match";
                    }else{
                        window.location.href = globalSiteUrl + "/admin/dashboard";
                    }
                } else {
                    $('#idAlertErrorMsg').show()
                    $('#idScriptErrorMsg').html(response.message)
                    alert_message_fadeout();
                }
                BtnReset();

            }
        });
        return false;
    });

Here after response output is

 <button type="submit" class="btn btn-primary btn-lg btn-block loader" id="idBtn" data-orignal-text="Verify">Verify</button>

I want to remove data-orignal-text in button after ajax success.

2

Answers


  1. To multiple issues on the page :

    var button = document.querySelectorAll('[data-orignal-text="Verify"]');
     button.forEach(element => {
      element.removeAttribute('data-orignal-text');
     })
    

    Just for one button issue :

    var button = document.querySelector('[data-orignal-text="Verify"]');
    element.removeAttribute('data-orignal-text');
    
    Login or Signup to reply.
  2. I checked you’re code there is no data-orignal-text attribute for the button in AJAX success or reject, can you more explain? because its redirects to the URL after ajax success or shows a popup message.

    But if you want to remove the attribute from the button then simply write the JQuery code I mention below:

    $('button').removeAttribute('data-orignal-text');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search