How to make JQuery-AJAX request synchronous

前端 未结 7 2023
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 09:55

How do i make an ajax request synchronous?

I have a form which needs to be submitted. But it needs to be submitted only when the user enters the correct password.

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 10:31

    Can you try this,

    var ajaxSubmit = function(formE1) {
    
                var password = $.trim($('#employee_password').val());
    
                 $.ajax({
                    type: "POST",
                    async: "false",
                    url: "checkpass.php",
                    data: "password="+password,
                    success: function(html) {
                        var arr=$.parseJSON(html);
                        if(arr == "Successful")
                        { 
                             **$("form[name='form']").submit();**
                            return true;
                        }
                        else
                        {    return false;
                        }
                    }
                });
                  **return false;**
            }
    

提交回复
热议问题