JQuery 라이브러리의 비동기 전송함수 ajax
CDN
// CDN
// head 안에 넣기
<head>
<title>Title</title>
// jquery cdn
<script src="https://code.jquery.com/jquery-latest.min.js">
</head>
기본 문법
$.ajax({
type: "", // 요청방식: get, post 방식인지 선택
url: "", // 요청주소: 주소url
data: "", // 넘겨줄 데이터
dataType: "", // 서버에서 보낸 응답을 받을 data 타입형식
contentType: 'application/json; charset=utf-8' ajax로 보낼때 data 타입
success: "", // 요청이 성공했을 때 실행
error: "", // 요청이 실패했을 때 실행
});
기본 예제)
$.ajax({
type: "POST",
url: "/member",
data: member,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(result) {
if(result){
alert("가입 완료");
}
},
error: function(xhr, status, error) {
alert("가입 실패!! \n\n" + xhr.responseText);
}
});
반응형
'JS > ajax' 카테고리의 다른 글
[ajax] 비동기 처리 - Axios (0) | 2023.10.25 |
---|---|
[ajax] json 형식으로 데이터 주고 받기 with SpringBoot (0) | 2023.10.24 |
[ajax]배열로 넘기기 (0) | 2023.05.15 |