• $.ajax()——超时设置


    getAjax: function (method, apiUrl, options, callback) {
            var xhr = $.ajax({
                type: method,
                url: apiUrl,
                data: options,
                timeout: 5000,          // 设置超时时间
                dataType: "json",
                beforeSend: function (xhr) {
                    $.showLoading();    // 数据加载成功之前,使用loading组件
                },
                success: function(json) {
                    $.hideLoading();    // 成功后,隐藏loading组件
                    if(callback && callback instanceof Function === "true") {
                        callback(json);
                    }
                },
                error: function (textStatus) {
                    console.error(textStatus);
                },
                complete: function (XMLHttpRequest,status) {
                    if(status == 'timeout') {
                        xhr.abort();    // 超时后中断请求
                        $.alert("网络超时,请刷新", function () {
                            location.reload();
                        })
                    }
                }
            })
        }
  • 相关阅读:
    C++学习笔记1——const
    反转二叉树
    pywinauto 使用
    pywinauto 的使用
    爬虫基础知识
    mongdb安装配置
    pyinstaller
    Python3.6+pyinstaller+Django
    py2exe安装使用
    cx_freeze的安装使用
  • 原文地址:https://www.cnblogs.com/moxiaowohuwei/p/7804077.html
Copyright © 2020-2023  润新知