jquery順序執行

 

function A() {
    writeMessage("Calling Function A");
    return $.ajax({
        url: "/scripts/S9/1.json",
        type: "GET",                    
        dataType: "json"
    });
}
 
 
function B(resultFromA) {
    writeMessage("In Function B. Result From A = " + resultFromA.data);
    return $.ajax({
        url: "/scripts/S9/2.json",
        type: "GET",
        dataType: "json"
    });
}
 
 
function C(resultFromB) {
    writeMessage("In Function C. Result From B =  " + resultFromB.data);
    return $.ajax({
        url: "/scripts/S9/3.json",
        type: "GET",
        dataType: "json"
    });
}
 
function D(resultFromC) {
    writeMessage("In Function D. Result From C = " + resultFromC.data);
}
 
A().then(B).then(C).then(D);
 
function writeMessage(msg) {
    $("#para").append(msg + "<br>");                 
}
相關文章
相關標籤/搜索