js 工具类
来源:互联网 发布:sai中文版官方下载mac 编辑:程序博客网 时间:2024/06/10 09:27
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"); }};
阅读全文
0 0
- utils.js,js工具类
- JS 工具类
- js工具类
- js 验证工具类
- JS时间工具类
- JS打印工具类
- js Math工具类
- js工具类汇总
- JS工具类
- js 工具类方法
- js 日期工具类
- js 工具类
- JS工具类
- js工具类
- JS工具类
- JS时间格式化工具类
- js时间格式化工具类
- JS日期处理工具类
- vagrant-安装教程及常见问题
- C++中,new/delete和malloc/free的区别
- 面试题——逻辑题
- cuda编程之 __syncthreads()
- MyBatis操作mysql配置和获取插入记录的自增主键
- js 工具类
- 创建数据库存储过程每天计划任务更新前台数据字段是否到期提醒
- 工具使用:Ngnix
- 菜鸟学算法--链表递归非递归
- 《Android源码设计模式》学习笔记之ImageLoader
- 线程 重入
- nodejs 开源项目
- UVALive
- 10.22