How to set timeout on $.ajax request and redo it if it takes too long?

前端 未结 4 1078
有刺的猬
有刺的猬 2021-01-20 16:26

Can someone show me a practical example on setting a timeout to my $.ajax request and redo the entire request if the first request is timed out, I\'ve read the docs and didn

4条回答
  •  心在旅途
    2021-01-20 16:47

    Try this

    var setTime = setTimeOut(function() {
        $.ajax({
            url: '/ajax/product.php',
            type: 'GET',
            data: {
                'product_id': product_id
            }
        }).beforeSend(function() {
            $('#details').html('
    '); }).done(function(data) { $('.iosSlider').fadeOut('fast'); thisprod.addClass('current'); $('#details').css({ opacity: 0 }).html(data).stop().animate({ left: 0, opacity: 1 }, 800); }); }, 2000);

提交回复
热议问题