Is it possible to check timeout on jQuery.post()?

后端 未结 2 1708
别那么骄傲
别那么骄傲 2020-12-31 14:01

I have this code requesting some folder info from a mysql DB:

function gotoDir(pmcat_id, pcat_id){
    $(\'#slideshowContainer\').html(\'

        
相关标签:
2条回答
  • 2020-12-31 14:43

    $.ajax has all the functions you need to accomplish what you are asking for:

    function gotoDir(pmcat_id, pcat_id) {
        $('#slideshowContainer').html('<img class="loader" src="/javascript/ajax-loader.gif">');
        $.ajax({
            type: "POST",
            url: "/publish/includes/content.includes/functions.slideshow.php",
            data: { updateSlideshowDir: 1, pmcat_id: pmcat_id, pcat_id: pcat_id },
            dataType: "json",
            timeout: 500, // in milliseconds
            success: function(data) {
                // process data here
            },
            error: function(request, status, err) {
                if(status == "timeout") {
                    gotoDir(pmcat_id, pcat_id);
                }
            }
        });
    }
    

    Please note that you don't need to set the timeout option unless you want to trigger the error method after a specific time you want to set.

    0 讨论(0)
  • 2020-12-31 14:54

    You should use $.ajax() and $.ajaxError(), then with "ajaxComplete" you can check if your request timedout, or succeded.

    Source: jQuery API

    0 讨论(0)
提交回复
热议问题