例如,如果我使用 jQuery 的 Ajax 执行此请求:
$(document).ready(function() {
$('#some_button').click(function() {
$.ajax({
url: '/some/request',
type: 'POST',
data: [{my: 'dummy', data: 'lata'}],
dataType: 'json',
async: true,
});
window.location.href = '/my/parent/location';
});
});
所以我感兴趣:
Will my action be completed on the server nevermind if I'm refreshing the page just right after the initial request is sent?
最佳答案
Ajax 是同步的。因此,无论请求如何,它都会立即重定向。
您可以在 Ajax 请求
的成功回调中调用它。
$(document).ready(function() {
$('#some_button').click(function() {
$.ajax({
url: '/some/request',
type: 'POST',
data: {my: 'dummy', data: 'lata'},
dataType: 'json',
success : function() {
window.location.href = '/my/parent/location';
}
});
});
});
关于javascript - 如果我在页面发送到服务器后立即重新加载或关闭页面,异步 Ajax 请求是否会完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13148431/