From 681d3af79d98c267cb61fca3141733c2f5b45cf3 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 17 Jan 2016 14:59:04 +0800 Subject: [PATCH] fixed cookie path problem --- assets/js/skin_utils.js | 36 ++++++++++++++++++++++++------------ libs/cookie.js | 6 +++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/assets/js/skin_utils.js b/assets/js/skin_utils.js index c08b1db0..a6228ba9 100755 --- a/assets/js/skin_utils.js +++ b/assets/js/skin_utils.js @@ -66,15 +66,27 @@ $("[title='Rotation']").click(function(){ }); $("#logout").click(function(){ - docCookies.removeItem("uname"); - docCookies.removeItem("token"); - window.location = "./index.php"; + $.ajax({ + type: "POST", + url: "../ajax.php?action=logout", + dataType: "json", + data: {"uname": docCookies.getItem('uname')}, + success: function(json) { + var path = "/" + document.URL.split("/").slice(-3)[0]; + docCookies.removeItem("uname", path); + docCookies.removeItem("token", path); + showMsg('alert-success', json.msg); + window.setTimeout(function(){ + window.location = "./index.php"; + }, 1000); + } + }); }); $("#upload").click(function(){ var skinFile = $("#skininput").get(0).files[0]; var capeFile = $("#capeinput").get(0).files[0]; - + var formData = new FormData(); if (skinFile) { formData.append('skinFile', skinFile); @@ -82,24 +94,24 @@ $("#upload").click(function(){ if (capeFile) { formData.append('capeFile', capeFile); } - + if (skinFile || capeFile) { $.ajax({ type: 'POST', url: './upload.php', contentType: false, - dataType: "json", + dataType: "json", data: formData, processData: false, - beforeSend: function() { - showMsg("alert-info", "Uploading..."); + beforeSend: function() { + showMsg("alert-info", "Uploading..."); }, success: function(json) { if (json[0].success == 1 && json[1].success == 1) { - showMsg("alert-success", "Successfully uploaded."); + showMsg("alert-success", "Successfully uploaded."); } if (json[0].success != 1) { - showMsg("alert-danger", "Error when uploading skin:\n"+json[0].msg); + showMsg("alert-danger", "Error when uploading skin:\n"+json[0].msg); } if (json[1].success != 1) { showMsg("alert-danger", "Error when uploading cape:\n"+json[1].msg); @@ -109,8 +121,8 @@ $("#upload").click(function(){ } else { showMsg("alert-warning", "No input file selected"); } - + }); - + diff --git a/libs/cookie.js b/libs/cookie.js index c5162a24..2be5f14e 100644 --- a/libs/cookie.js +++ b/libs/cookie.js @@ -1,5 +1,5 @@ -/** -** cookie.js +/** +** cookie.js ** https://developer.mozilla.org/en-US/docs/DOM/document.cookie */ var docCookies = { @@ -40,4 +40,4 @@ var docCookies = { for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); } return aKeys; } -}; \ No newline at end of file +};