分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

js 工具类

发布时间:2023-09-06 01:19责任编辑:彭小芳关键词:js

Log

/** * Created by e2670 on 2017/10/6. *//** * Log utils */var FLog = { ???isLogPos: true, ???/** ????* trace log ????* @param params ????*/ ???t: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.trace(params); ???}, ???/** ????* debug log ????* @param params ????*/ ???d: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.debug(params); ???}, ???/** ????* info log ????* @param params ????*/ ???i: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.info(params); ???}, ???/** ????* warn log ????* @param params ????*/ ???w: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.warn(params); ???}, ???/** ????* error log ????* @param params ????*/ ???e: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.error(params); ???}, ???/** ????* fatal log ????* @param params ????*/ ???f: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.fatal(params); ???}, ???/** ????* trace log ????* @param params ????*/ ???trace: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.trace(params); ???}, ???/** ????* debug log ????* @param params ????*/ ???debug: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.debug(params); ???}, ???/** ????* info log ????* @param params ????*/ ???info: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.info(params); ???}, ???/** ????* warn log ????* @param params ????*/ ???warn: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.warn(params); ???}, ???/** ????* error log ????* @param params ????*/ ???error: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.error(params); ???}, ???/** ????* fatal log ????* @param params ????*/ ???fatal: function (params) { ???????if (FLog.isLogPos) { ???????????console.log(FLog.getLogLine()); ???????} ???????console.fatal(params); ???}, ???getLogLine: function () { ???????try { ???????????Zzz.Zzz; ???????} catch (ex) { ???????????var exMsg = ex.stack.split("\n"); ???????????// var msg = exMsg[3].split("("); ???????????// return "(" + msg[msg.length - 1]; ???????????return exMsg[3]; ???????} ???}};

HTTP

/** * Created by e2670 on 2017/10/21. * Http请求工具类 */var FwHttp = { ???/** ????* 基于XMLHttpRequest封装 ????*/ ???/** ????* get请求异步获取 ????* @param url ????* @param callSuc ????* @param callErr ????* exam: FwHttp.getAsync(url,callbackSuccess,callbackError); ????*/ ???getAsync:function (url,callSuc,callErr) { ???????var xmlhttp = new XMLHttpRequest(); ???????xmlhttp.open("GET", url, true); ???????xmlhttp.send(); ???????// 异步方法回调 ???????xmlhttp.onreadystatechange = function () { ???????????if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { ???????????????callSuc(xmlhttp.responseText); ???????????}else { ???????????????callErr(xmlhttp.responseText); ???????????} ???????} ???}, ???/** ????* get请求同步获取 ????* @param url ????* exam:var res = FwHttp.getSync(url); ????*/ ???getSync:function (url) { ???????var xmlhttp = new XMLHttpRequest(); ???????xmlhttp.open("GET", url, false); ???????xmlhttp.send(); ???????return xmlhttp.responseText; ???}, ???/** ????* post请求异步提交 ????* @param url ????* @param dataStr ????* @param contentType ????* @param callSuc ????* @param callErr ????*/ ???postAsync:function (url,dataStr,contentType,callSuc,callErr) { ???????var xmlhttp = new XMLHttpRequest(); ???????xmlhttp.open("POST", commitUrl, true); ???????xmlhttp.setRequestHeader("Content-type", contentType); ???????xmlhttp.send(dataStr); ???????xmlhttp.onreadystatechange = function () { ???????????if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { ???????????????callSuc(xmlhttp.responseText); ???????????}else { ???????????????callErr(xmlhttp.responseText); ???????????} ???????} ???}, ???/** ????* post请求同步提交 ????* @param url ????* @param dataStr ????* @param contentType ????* @returns {string} ????*/ ???postSync:function (url,dataStr,contentType) { ???????var xmlhttp = new XMLHttpRequest(); ???????xmlhttp.open("POST", commitUrl, false); ???????xmlhttp.setRequestHeader("Content-type", contentType); ???????xmlhttp.send(dataStr); ???????return xmlhttp.responseText; ???}, ???/** ????* post请求异步提交 ????* @param url ????* @param dataStr ????* @param callSuc ????* @param callErr ????* FwHttp.postJsonAsync(url,jsonStr,callbackSuccess,callbackError); ????*/ ???postJsonAsync:function (url,dataStr,callSuc,callErr) { ???????FwHttp.postAsync(url,dataStr,"application/json",callSuc,callErr); ???}, ???/** ????* post请求同步提交 ????* @param url ????* @param dataStr ????* @returns {string} ????* exam: var res = FwHttp.postJsonSync(url,jsonStr); ????*/ ???postJsonSync:function (url,dataStr) { ???????return FwHttp.postSync(url,dataStr,"application/json"); ???}};

js 工具类

原文地址:http://www.cnblogs.com/zhen-android/p/7712719.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved