jQuery Ajax doesn’t return success in some browsers, such as the Facebook messenger

  ajax, javascript, jquery

I have an Ajax registration form, I sent it out to students on the Facebook messenger app, many of them complained that it stays showing the loader for a long time without even returning a response, I tried it myself and it does that indeed, it doesn’t return the success function at all, however it works fine on iOS Safari and Google Chrome on my PC, what is the problem that I have in my code?

$("#last").click(function(event) {


    var email = $("#email").val().trim();
    var studentid = $("#studentid").val().trim();
    var password = $("#password").val().trim();
    var confpassword = $("#confpassword").val().trim();
    var firstname = $("#firstname").val().trim();
    var secondname = $("#secondname").val().trim();
    var thirdname = $("#thirdname").val().trim();
    var lastname = $("#lastname").val().trim();
    var phonenum = $("#phonenum").val().trim();
    var address = $("#address").val().trim();
    var comm = document.getElementById("comm").value;
    var passportnum = $("#passportnum").val().trim();
    var passporttype = $("#passporttype").val().trim();
    var selectyear = document.getElementById("selectyear").value;
    var PassportRadio = $("input[name='Radio']:checked").val();




    if (email != "" && studentid != "" && password != "" && confpassword != "" && firstname != "" && secondname != "" && thirdname != "" && lastname != "" && phonenum != "" && address != "" && comm != "" && selectyear != "") {
        if (password == confpassword) {
            if (password.length >= 8) {
                if (studentid.length == 8) {
                    if (PassportRadio == "yes" && (passportnum == "" || passporttype == "")) {

                        swal("Error", "Please fill the passport fields!", "error");
                    } else {

                        $.ajax({
                            type: 'POST',
                            url: "apply.php",
                            data: {
                                email: email,
                                studentid: studentid,
                                password: password,
                                firstname: firstname,
                                secondname: secondname,
                                thirdname: thirdname,
                                lastname: lastname,
                                phonenum: phonenum,
                                address: address,
                                comm: comm,
                                selectyear: selectyear,
                                passportnum: passportnum,
                                passporttype: passporttype
                            },
                            dataType: 'text',
                            beforeSend: function() {
                                document.getElementById("loader").style.display = "block";
                                $('#last').attr('disabled', 'disabled');

                            },
                            success: function(response) {
                                alert(response);
                                if (response == 2) {
                                    document.getElementById("loader").style.display = "none";
                                    swal("Error", "Error connecting to the database", "error");

                                } else if (response == 1) {
                                    document.getElementById("loader").style.display = "none";
                                    $("#progressbar li").eq($("fieldset").index("confirm")).addClass("active");

                                    current_fs = $(this).parent();
                                    var html = ' <div class="form-card">
                                    <h2 class="fs-title text-center">Thank You!</h2> <br><br> 
                                   <div class="row justify-content-center"> 
                                        <div class="col-3"> <img src="https://img.icons8.com/color/96/000000/ok--v2.png" class="fit-image"> </div>
                                    </div> <br><br>
                                    <div class="row justify-content-center">
                                        <div class="col-7 text-center">
                                            <h5>You Have Successfully Requested a membership for the new term! <br>  
                                            Patience is the key! Please track your Request later <a href="Pending.php">Here.</a> </h5>
                                        </div>
                                    </div>
                                </div>';
                                    next_fs = $(".succ").html(html);
                                    //Add Class Active 

                                    //show the next fieldset
                                    next_fs.show();
                                    //hide the current fieldset with style
                                    current_fs.animate({
                                        opacity: 0
                                    }, {
                                        step: function(now) {
                                            // for making fielset appear animation
                                            opacity = 1 - now;

                                            current_fs.css({
                                                'display': 'none',
                                                'position': 'relative'
                                            });
                                            next_fs.css({
                                                'opacity': opacity
                                            });
                                        },
                                        duration: 600
                                    });
                                    setTimeout(function() {
                                        window.location = "https://pmsa-jerusalem.com/home.php";
                                    }, 30000);


                                } else if (response == 3) {
                                    document.getElementById("loader").style.display = "none";
                                    swal("Error", "You entered an invalid email!", "error");
                                    $('#last').removeAttr('disabled');


                                } else if (response == 5) {
                                    document.getElementById("loader").style.display = "none";
                                    swal("Error", "This email exists for another user, use another one!", "error");
                                    $('#last').removeAttr('disabled');

                                } else if (response == 4) {
                                    document.getElementById("loader").style.display = "none";

                                    $("#progressbar li").eq($("fieldset").index("confirm")).addClass("active");

                                    current_fs = $(this).parent();
                                    var html = ' <div class="form-card">
                                    <h2 class="fs-title text-center">Thank You!</h2> <br><br> 
                                   <div class="row justify-content-center"> 
                                        <div class="col-3"> <img src="https://img.icons8.com/color/96/000000/ok--v2.png" class="fit-image"> </div>
                                    </div> <br><br>
                                    <div class="row justify-content-center">
                                        <div class="col-7 text-center">
                                            <h5>You Have Successfully Updated your information and requested a membership for the new term! <br>  
                                            Patience is the key! Please track your Request later <a href="Pending.php">Here.</a> </h5>
                                        </div>
                                    </div>
                                </div>';
                                    next_fs = $(".succ").html(html);
                                    //Add Class Active 

                                    //show the next fieldset
                                    next_fs.show();
                                    //hide the current fieldset with style
                                    current_fs.animate({
                                        opacity: 0
                                    }, {
                                        step: function(now) {
                                            // for making fielset appear animation
                                            opacity = 1 - now;

                                            current_fs.css({
                                                'display': 'none',
                                                'position': 'relative'
                                            });
                                            next_fs.css({
                                                'opacity': opacity
                                            });
                                        },
                                        duration: 600
                                    });
                                    setTimeout(function() {
                                        window.location = "https://pmsa-jerusalem.com/home.php";
                                    }, 30000);
                                } else if (response == 6) {
                                    document.getElementById("loader").style.display = "none";
                                    swal("Error", "You already signed up!", "error");
                                    $('#last').removeAttr('disabled');

                                }

                            }
                        });
                    }
                } else {

                    document.getElementById("loader").style.display = "none";
                    swal("Error", "Your Student ID must be 8 digits", "error");
                    $('#last').removeAttr('disabled');

                }


            } else {
                document.getElementById("loader").style.display = "none";

                swal("Error", "Your password must be 8 digits or more", "error");

            }
        } else {
            document.getElementById("loader").style.display = "none";
            swal("Error", "The passwords you entered does not match...", "error");

        }
    } else {
        document.getElementById("loader").style.display = "none";
        swal("Error", "Please fill all the fields!", "error");
    }
});

Source: Ask Javascript Questions

LEAVE A COMMENT