웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
[AJAX]DB 해당값을 검색하기
2014.09.24 12:16
<!------------------------- search.asp ------------------------------------------->
<!--#include virtual="/supervisor/include/incl_include_01.asp"--> <!-- DB 연결 -->
<html>
<head>
<meta search</title>
<script language="javascript" type="text/javascript">
var request = null;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
if (request == null)
alert("Error creating request object!");
function Info() {
var query = document.getElementById("query").value;
var url = "query.asp?names=" + escape(query);
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
/* Get the response from the server */
var name_value = request.responseText;
if (name_value=="No"){
alert(" 가입된 이름 입니다.\n 다른 이름을 넣어주세요 ~!!")
document.getElementById("query").value = "";
document.getElementById("query").focus();
return ;
}
/* Update the HTML web form */
document.getElementById("name").value = name_value;
} else
alert("Error! Request status is " + request.status);
}
}
</script>
</head>
<body>
<p>아작스</p>
<p>회원 이름 :
<input type="text" size="14" name="query" id="query" onChange="Info();" />
</p>
<p>검색한 이름 : <input type="text" name="name" id="name"></p>
<p>가입된 회원</p>
<%
db_connect()
sql ="select mem_name from table_name" '현재 가입되어있는 회원 이름 불러오기
rs.open sql, db, 1
do while rs.eof=false
response.write rs("mem_name") &"
"
rs.movenext
loop
%>
</body>
</html>
<!--------------------------------------- query.asp ------------------------------------------>
<!--#include virtual="/supervisor/include/incl_include_01.asp"--> <!--- DB 연결 -->
<%
Session.CodePage = 949 '한글로 인코딩 (네이버에서 펌)
Response.CharSet = "euc-kr"
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "Expires","0"
db_connect()
na = Trim(request("names"))
na = Replace(na,"'","") ' 보안상... ㅡ.ㅡ;;;
sql ="select * from table_name where mem_name = '"& na &"'"
rs.open sql, db, 1
if rs.eof or rs.bof then
mem_into = na '회원 가입이 되어있지 않다면...
else
mem_into = "No" '회원 가입이 되어있다면...
end if
rs.close
response.write mem_into
%>