ajax请求完成后的Continue函数

Continue function after ajax request has been completed

本文关键字:Continue 函数 请求 ajax      更新时间:2023-09-26

我想知道是否有可能让函数调用具有ajax请求的函数,并在ajax请求完成时继续执行。下面是示例伪代码:

function func1(){
    //do things
    func2();
    //**How would I get this code to execute after the ajax request is finished.
}
function func2(){
    $.ajax({
        url: "test.html",
        context: document.body,
        success: function(){
            //do some things
        }
    });

我不想在回调函数中执行所有内容,因为这个函数在循环中被调用多次。

谢谢!

你有两个选择。

  1. 为AJAX调用后发生的处理使用回调函数。
  2. 使用同步的"JAX"调用…记住,AJAX中的A是异步的。