function getRootPath() { var curWwwPath = window.document.location.href; var pathName = window.document.location.pathname; // console.log(pathName); var pos = curWwwPath.indexOf(pathName); var localhostPath = curWwwPath.substring(0, pos); // 这种写法,限制项目名称必须包含gamesys,wg var projectName = pathName.substring(0, pathName.substr(0).lastIndexOf('gamesys/')) + 'gamesys/'; // console.log(projectName); projectName = projectName.substring(0, projectName.substr(0).lastIndexOf('/') + 1); return localhostPath + projectName; } function getProviderUrl(tag) { return getRootPath() + "app/providers/" + tag + ".php"; } /** * 获取cookies * @param {Object} name */ function getCookie(key) { var arr = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)(;|$)")); if (arr != null) { return unescape(arr[2]); } else { return null; } } /** * 向服务端post数据 * @param {Object} url * @param {Object} body * @param {Object} suc */ function post(url, body, suc) { body.account = getCookie("account"); $.ajax({ type: "post", url: url, async: true, data: body, success: function(token) { // 解析回传的数据 //alert(token); token = JSON.parse(token); if (token.err == 0) { suc(token.data); } else { onError(token); } } }); } function onError(token) { if (token.err == 6001) { alert(token.errMsg); location.href = "login.html"; } }