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(); }) } } }) }