jQuery .then() 与简单的顺序函数
jQuery .then() vs simple sequential functions
谁能解释一下两者的区别:
$.get( "test.php" ).then(
function() {
$.ajax({
method: "POST",
url: "test.php"
});
}
);
和
$.get( "test.php" );
$.ajax({
method: "POST",
url: "some.php"
});
在我的具体情况下,我需要先进行 GET 调用,然后才能进行 AJAX POST 调用( 到相同的 url) 在 IE / Edge 中修复 a bug。
AJAX 请求是基于事件的。它们被创建并且 javascript 继续执行。当 AJAX 状态改变时,就是回调函数执行的时候。
两种脚本的区别详述如下:
// Execution On GET Success
$.get( "test.php" ).then( // | Creates GET
function() { // | Adds Callback | Triggers Callback
$.ajax({ // | | Creates POST
method: "POST", // | |
url: "test.php" // | |
}); // | |
} // | |
); // |
// \_/
// Execution
$.get( "test.php" ); // | Creates GET
$.ajax({ // | Creates POST
method: "POST", // |
url: "some.php" // |
}); // |
// \_/
谁能解释一下两者的区别:
$.get( "test.php" ).then(
function() {
$.ajax({
method: "POST",
url: "test.php"
});
}
);
和
$.get( "test.php" );
$.ajax({
method: "POST",
url: "some.php"
});
在我的具体情况下,我需要先进行 GET 调用,然后才能进行 AJAX POST 调用( 到相同的 url) 在 IE / Edge 中修复 a bug。
AJAX 请求是基于事件的。它们被创建并且 javascript 继续执行。当 AJAX 状态改变时,就是回调函数执行的时候。
两种脚本的区别详述如下:
// Execution On GET Success
$.get( "test.php" ).then( // | Creates GET
function() { // | Adds Callback | Triggers Callback
$.ajax({ // | | Creates POST
method: "POST", // | |
url: "test.php" // | |
}); // | |
} // | |
); // |
// \_/
// Execution
$.get( "test.php" ); // | Creates GET
$.ajax({ // | Creates POST
method: "POST", // |
url: "some.php" // |
}); // |
// \_/