if (typeof module === 'object') { window.jQuery = window.$ = module.exports; } /* * @Author: Zh_Strong * @Date: 2023-06-17 18:06:38 * @LastEditTime: 2023-06-17 18:27:08 * @LastEditors: Zh_Strong * @Description: Zh_Strong * @FilePath: \AJAX\jq-3.6.1\fofJqCode1.0.1.js */ function FoFJsCodeJQAjax(Url, IfType, Data, timeout, contentType_, application, ifDataObj) { timeout = typeof timeout !== 'undefined' ? timeout : 5000; ifDataObj = typeof ifDataObj !== 'undefined' ? ifDataObj : []; if (contentType_ == undefined) { application = typeof application !== 'undefined' ? application : []; if (IfType == true) { IfType = "POST"; } else { IfType = "GET"; } let RetData = ""; $.ajax({ url: Url, data: Data, async: false, type: IfType, timeout: timeout, beforeSend: function (AJAX) { for (let index = 0; index < application.length; index++) { AJAX.setRequestHeader(application[index]["名称"], application[index]["值"]); } }, success: function (result, textStatus, xhr) { if (ifDataObj.length >= 1) { RetData = {} RetData["返回数据"] = result for (let index = 0; index < ifDataObj.length; index++) { RetData[ifDataObj[index]] = xhr.getResponseHeader(ifDataObj[index]) RetData["所有协议头"] = xhr.getAllResponseHeaders() } } else { RetData = result; } }, complete: function (XMLHttpRequest, status) { if (status == 'timeout') { // 判断超时后 执行 RetData = "错误请求" } }, error: function (xhr, status, error) { RetData = "错误请求" } }); return RetData; } else { application = typeof application !== 'undefined' ? application : []; if (IfType == true) { IfType = "POST"; } else { IfType = "GET"; } let RetData = ""; $.ajax({ url: Url, data: Data, async: false, type: IfType, timeout: timeout, contentType: contentType_, beforeSend: function (AJAX) { for (let index = 0; index < application.length; index++) { AJAX.setRequestHeader(application[index]["名称"], application[index]["值"]); } }, success: function (result, textStatus, xhr) { if (ifDataObj.length >= 1) { RetData = {} RetData["返回数据"] = result for (let index = 0; index < ifDataObj.length; index++) { RetData[ifDataObj[index]] = xhr.getResponseHeader(ifDataObj[index]) RetData["所有协议头"] = xhr.getAllResponseHeaders() } } else { RetData = result; } }, complete: function (XMLHttpRequest, status) { if (status == 'timeout') { // 判断超时后 执行 RetData = "错误请求" } }, error: function (xhr, status, error) { RetData = "错误请求" } }); return RetData; } } function FoFJsCodeJQAjax2(Url, IfType, funCk, Data, timeout, contentType_, application, ifDataObj) { timeout = typeof timeout !== 'undefined' ? timeout : 5000; application = typeof application !== 'undefined' ? application : []; ifDataObj = typeof ifDataObj !== 'undefined' ? ifDataObj : []; if (IfType == true) { IfType = "POST"; } else { IfType = "GET"; } if (contentType_ == undefined) { $.ajax({ url: Url, data: Data, type: IfType, timeout: timeout, beforeSend: function (AJAX) { for (let index = 0; index < application.length; index++) { AJAX.setRequestHeader(application[index]["名称"], application[index]["值"]); } }, success: function (result, textStatus, xhr) { if (funCk != undefined) { if (ifDataObj.length >= 1) { let RetData = {} RetData["返回数据"] = result for (let index = 0; index < ifDataObj.length; index++) { RetData[ifDataObj[index]] = xhr.getResponseHeader(ifDataObj[index]) RetData["所有协议头"] = xhr.getAllResponseHeaders() } funCk(RetData); } else { funCk(result); } } }, complete: function (XMLHttpRequest, status) { if (status == 'timeout') { // 判断超时后 执行 if (funCk != undefined) { funCk("错误请求"); } } }, error: function (xhr, status, error) { if (funCk != undefined) { funCk("错误请求"); } } }); } else { $.ajax({ url: Url, data: Data, type: IfType, timeout: timeout, contentType: contentType_, beforeSend: function (AJAX) { for (let index = 0; index < application.length; index++) { AJAX.setRequestHeader(application[index]["名称"], application[index]["值"]); } }, success: function (result, textStatus, xhr) { if (funCk != undefined) { if (ifDataObj.length >= 1) { let RetData = {} RetData["返回数据"] = result for (let index = 0; index < ifDataObj.length; index++) { RetData[ifDataObj[index]] = xhr.getResponseHeader(ifDataObj[index]) RetData["所有协议头"] = xhr.getAllResponseHeaders() } funCk(RetData); } else { funCk(result); } } }, complete: function (XMLHttpRequest, status) { if (status == 'timeout') { // 判断超时后 执行 if (funCk != undefined) { funCk("错误请求"); } } }, error: function (xhr, status, error) { if (funCk != undefined) { funCk("错误请求"); } } }); } }