jquery中的ajax 默认情况下为异步请求,即 async:true,可以通过设置参数 asycn:false 到使其同步

                                    $.ajax({
                                        url: 'www.test.com/test/test',
                                        type: 'POST',
                                        data: {name:"test"}
                                        async: false,
                                        error: function() {
                                            console.log('error');
                                        },
                                        success: function(resp) {
                                            console.log('success');
                                        }
                                    });

注意:如果你有这种操作。调用ajax 之前写了一个 flag = false; 但是在ajax 的success 回调中 设置 flag = true 之类的操作,在ajax 异步状态下,是无法得到想要的结果的。
因为ajax 默认是异步,等你执行后面的操作完成之后,有可能才 执行回调 flag = true 操作!!

相关文章:

  • 2021-09-12
  • 2021-12-10
  • 2021-12-10
  • 2021-12-27
  • 2022-12-23
  • 2021-09-25
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-02-21
相关资源
相似解决方案