고마구의 개발 블로그
240714 12주차 일요일 미니 프로젝트 쇼핑몰 제작 10 본문
[Javascript] Ajax 개념, 사용 (회원가입시 ID 중복체크)
프론트와 백이 통신함에 있어 Ajax라는 것을 사용한다. 우선 Ajax란? 간단히 말하면 비동기 Javascript와 XML을 말한다. XMLHttpRequest 객체를 이용해서 JSON, XML, HTML, TEXT와 같은 데이터를 서버와 주고받는
jaeano.tistory.com
ajax 이용한 아이디 중복 체크
close함수
https://blog.naver.com/PostView.nhn?blogId=innoc99&logNo=140055334056
JavaScript에서 close()함수를 사용하자! 총정리!
우선 JavaScript의 Window객체에는 Open()과 Close()라는 함수가 있다.. 각각의 함수는 (다들 아시겠...
blog.naver.com
function checkID() { //중복아이디 체크
const element = document.getElementById('check');
let id = document.getElementById("id").value;
const httpRequest=new XMLHttpRequest();
httpRequest.onreadystatechange=function(){
if(httpRequest.readyState==4 && httpRequest.status==200){
const response=httpRequest.responseText;
console.log(response);
let str="";
if(response=="true"){
str="중복되었습니다";
}else{
str="사용가능합니다.";
}
element.innerText = '입력한 아이디는 '+str;
}else{
console.log("나쁜");
}
};
httpRequest.open("GET",'/jdbc07_shoppingmall/user/join_pro.user?user_id='+id,true);
httpRequest.responseType="text";
httpRequest.send(null);
}
중복체크 버튼 밑에 <div id="check"></div> 추가
컨트롤러 서블릿
}else if(command.equals("/user/join_pro.user")) {
String id=request.getParameter("user_id");
if(customerService.selectID(id).equals(id)){
System.out.println(id);
response.getWriter().print("true");
}else {
response.getWriter().print("false");
}
return;
리턴없으면 밑에 줄이 실행돼서 리턴있어야함
'KDT풀스택과정 공부' 카테고리의 다른 글
| 240716 13주차 화요일 - Spring 02 (0) | 2024.07.16 |
|---|---|
| 240715 13주차 월요일 - 스프링 01 (0) | 2024.07.15 |
| 240712 12주차 금요일 미니 프로젝트 쇼핑몰 제작 09 (0) | 2024.07.12 |
| 240711 12주차 목요일 - 미니 프로젝트 쇼핑몰 제작 08 (0) | 2024.07.11 |
| 240710 12주차 수요일 - 미니 프로젝트 쇼핑몰 제작 07 (0) | 2024.07.10 |