ajax

채상혁·2022년 2월 9일
0

Spring

목록 보기
3/18

ajax란...

클라이언트에서 서버와 비동기 통신을 진행하는 ajax 함수.(라이브러리)
$.ajax({object literal});

					type : 'post',
					url : '/user/',
					contentType : 'application/json',
					dataType : 'text',
					data : JSON.stringify(user),
					success : function(result) {
						//joinSuccess 전달됨 컨트롤러에서
						console.log('통신 성공:'+ result);
						alert('회원 가입을 환영합니다.');
						location.href = "/"; //홈화면으로 이동.
					},
					error : function(error, status){
						alert("회원 가입 실패!")
					} 
					

자바스크립트 객체를 JSON(JAVAscript Object Notation) 문자열로 변환해 주는 메서드 : JSON.stringify(객체 리터럴);

type, url ,contentType, dataType, data , success, error 에 순서가 정해져 있는 것은 아니다. success와 error -> function(parameter)를 선언하면 parameter 값으로 결과가 전송된다.

0개의 댓글