Fix: send request / receive json data
This commit is contained in:
@@ -25,11 +25,11 @@
|
||||
let maestroName = $("#search_name").val();
|
||||
|
||||
if(maestroName.length === 0) {
|
||||
// $("#search_name_notice").val("학생 이름을 입력하세요.");
|
||||
$("#error_message").text("학생 이름을 입력하세요.");
|
||||
$("#search_name").focus();
|
||||
}
|
||||
|
||||
loadMaestroList($maestroName);
|
||||
loadMaestroList(maestroName);
|
||||
}
|
||||
|
||||
function loadMaestroList($maestroName) {
|
||||
@@ -43,6 +43,7 @@
|
||||
// console.log(xhr.responseText.length);
|
||||
if(xhr.responseText.length === 0 || xhr.responseText === null) {
|
||||
console.log("no data from server");
|
||||
$("#error_message").text("서버에서 요청을 수행하지 못했습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,16 +52,19 @@
|
||||
|
||||
if(replyJSON === null) {
|
||||
console.log("no data from server");
|
||||
$("#error_message").text("서버에서 데이터가 넘어오지 않았습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
|
||||
console.log(replyJSON["ERROR"]);
|
||||
$("#error_message").text(replyJSON["ERROR"]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(replyJSON["RESULT"] === "fail") {
|
||||
console.log(replyJSON["RESULT"]);
|
||||
$("#error_message").text(replyJSON["ERROR"]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,6 +142,7 @@
|
||||
// console.log(xhr.responseText.length);
|
||||
if(xhr.responseText.length === 0 || xhr.responseText === null) {
|
||||
console.log("no data from server");
|
||||
$("#error_message").text("서버에서 요청을 수행하지 못했습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -146,20 +151,24 @@
|
||||
|
||||
if(replyJSON === null) {
|
||||
console.log("no data from server");
|
||||
$("#error_message").text("서버에서 데이터가 넘어오지 않았습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
|
||||
console.log(replyJSON["ERROR"]);
|
||||
$("#error_message").text(replyJSON["ERROR"]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(replyJSON["RESULT"] === "fail") {
|
||||
console.log(replyJSON["RESULT"]);
|
||||
$("#error_message").text(replyJSON["ERROR"]);
|
||||
return;
|
||||
}
|
||||
|
||||
loadMaestroList("");
|
||||
$("#error_message").text("마에스트로 계정이 정상적으로 등록되었습니다.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,19 +186,24 @@
|
||||
</header>
|
||||
|
||||
<section id="section">
|
||||
<span id="search_maestro_name">
|
||||
<h1>검색</h1>
|
||||
<div id="error_message">
|
||||
</div>
|
||||
|
||||
마에스트로 이름
|
||||
<input type="text" id="search_name"><input type="submit" name="찾기" onClick="searchMaestro()"><br/>
|
||||
<br/>
|
||||
</span>
|
||||
<div>
|
||||
<span id="search_maestro_name">
|
||||
<h1>검색</h1>
|
||||
|
||||
<span id="search_result">
|
||||
검색 결과
|
||||
<div id="maestro_list_result_contents">
|
||||
</div>
|
||||
</span>
|
||||
마에스트로 이름
|
||||
<input type="text" id="search_name"><input type="submit" name="찾기" onClick="searchMaestro()"><br/>
|
||||
<br/>
|
||||
</span>
|
||||
|
||||
<span id="search_result">
|
||||
검색 결과
|
||||
<div id="maestro_list_result_contents">
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
+26
-28
@@ -10,6 +10,7 @@
|
||||
|
||||
<script type="text/javascript" src="./../../../resources/jquery/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript" src="./../js/main.js"></script>
|
||||
<script type="text/javascript" src="./../js/request_server.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
sessionStorage.setItem("maestroID", -1);
|
||||
@@ -21,30 +22,25 @@
|
||||
let name = $("#maestro_name").val();
|
||||
let password = $("#password").val();
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/login.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_name=" + name + "&password=" + password);
|
||||
xhr.onload = function() {
|
||||
if(xhr.readyState === 4 && xhr.status === 200) {
|
||||
let replyJSON = JSON.parse(xhr.responseText);
|
||||
// console.log(replyJSON);
|
||||
|
||||
// if(replyJSON !== null)
|
||||
// console.log(replyJSON);
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/maestro/login.php",
|
||||
"maestro_name=" + name + "&password=" + password,
|
||||
|
||||
// if(replyJSON["MaestroID"] !== undefined)
|
||||
// console.log(replyJSON["MaestroID"]);
|
||||
(jsonData) => {
|
||||
maestroID = jsonData["MaestroID"];
|
||||
sessionStorage.setItem("maestroID", maestroID);
|
||||
location.href = 'admin_register_list.html';
|
||||
},
|
||||
|
||||
if(replyJSON !== null && replyJSON["MaestroID"] !== undefined && replyJSON["MaestroID"] !== null) {
|
||||
maestroID = replyJSON["MaestroID"];
|
||||
sessionStorage.setItem("maestroID", maestroID);
|
||||
location.href = 'admin_register_list.html';
|
||||
} else {
|
||||
$("#error_message").val(replyJSON["ERROR"]);
|
||||
(errorMessage) => {
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -54,17 +50,19 @@
|
||||
|
||||
<body bgcolor="white">
|
||||
|
||||
<div>
|
||||
관리자 아이디
|
||||
<input type="text" id="maestro_name" name="maestro_name"><br/>
|
||||
암호
|
||||
<input type="password" id="password" name="password"><br/>
|
||||
</div>
|
||||
<div>
|
||||
관리자 아이디
|
||||
<input type="text" id="maestro_name" name="maestro_name"><br/>
|
||||
암호
|
||||
<input type="password" id="password" name="password"><br/>
|
||||
</div>
|
||||
|
||||
<div class="col alignCenter">
|
||||
<a id="login" class="btn btn-sea width400" onClick="login()">로그인</a>
|
||||
</div>
|
||||
<div class="col alignCenter">
|
||||
<a id="login" class="btn btn-sea width400" onClick="login()">로그인</a>
|
||||
</div>
|
||||
|
||||
<div id="error_message">
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user