gpt4 book ai didi

javascript - 在没有 $.ajax() 的 AJAX 上设置超时

转载 作者:行者123 更新时间:2023-11-30 13:13:34 25 4
gpt4 key购买 nike

我想在加载数据 2 秒后设置超时。我是 ajax 的新手,所以请通过我的代码进行澄清...因为我已经看到很多(在 ajax 上设置超时)答案,但每个答案都是通过 $.ajax() 完成的。

我可以通过 .load() 做什么?可以吗?

我的 AJAX 代码 1:

// Start of our new ajax code
if (!url) {
url = jQuery('#product_addtocart_form').attr('action');
}
url = url.replace("checkout/cart","ajax/index"); // New Code
var data = jQuery('#product_addtocart_form').serialize();
data += '&isAjax=1';
jQuery('#ajax_loader').show();
try {
jQuery.ajax( {
url : url,
dataType : 'json',
type : 'post',
data : data,
success : function(data) {
jQuery('#ajax_loader').hide();
parent.setAjaxData(data,true);
}
});
jQuery("#productOptions").modal('hide');
} catch (e) {
//alert(e);
}
// End of our new ajax code

2:

// AJAX product options modal
$('.optionsTrigger').on('click', function() {
var target, url;
target = $(this).attr('data-target');
url = $(this).attr('href');
$(target).load(url, function(){
$(target).modal({
show: true
});
});
});
$('#productOptions').on('hidden', function() {
$('#productOptions').html('<img src="<?php echo $this->getSkinUrl("img/loading.gif"); ?>" id="optionsLoading" />');

window.setTimeout("Tick()", 2000);

function Tick()
{

}
});

最佳答案

jQuery 有 ajaxSetup() method可用的。您可以在那里将所有选项设置为普通的 ajax() 方法,包括 timeout 选项。当您通过 load() 调用 AJAX 请求时,那里设置的设置也应该可用。

关于javascript - 在没有 $.ajax() 的 AJAX 上设置超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12952570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com