JAVA(STS)

[java] jQuery - 비동기 통신 Ajax 코드 의미

걍작 2022. 2. 18. 10:12

#ajax 통신

//비동기식 Ajax를 이용하여 HTTP 요청을 전송
$.ajax({ 
	url : 'http://localhost:8090/oracleHR/json_phoneCheck.do', // 클라이언트가 HTTP 요청을 보낼 서버의 URL 주소 >> 로컬주소
	type : 'get',// HTTP 요청 메소드(GET, POST 등) >> GET
	data : {phone:$('#phone_number').val()},// HTTP 요청과 함께 서버로 보낼 데이터 >> {식별자:데이터}
	dataType : "json",// 서버에서 보내줄 데이터의 타입 >> JSON type
	success : function(responseData) { //성공시 실행 코드
		console.log('success');
		console.log(responseData);//{email: 'Lee1004'}
		let result = '';

		if ($('#phone_number').val() === responseData.phone_number) {
			result = '중복된 전화번호 입니다.';
		} else {
			result = '사용가능한 전화번호 입니다.';
		}

		$('#result_phoneCheck').text(result);

	 },
     error : function(jqXHR, textStatus, errorThrown) {//오류 발생시 실행코드
		alert("ajax error : " + textStatus + "\n" + errorThrown);//오류 내용 안내
	 }
});