728x90
출처:
https://www.youtube.com/watch?v=XbeEc_uRCsY
jquery ajax 홈페이지 예제
$.ajax({
//회원가입 수행 요청
type: "POST",
url: "/joinForm",
data: JSON.stringify(data), //http body 데이터
contentType: "application/json; charset=utf-8", //body데이터가 어떤 타입인지(MIME)
dataType: "json", // 요청을 서버로 해서 응답이 왔을 때 기본적으로 모든 것이 문자열(생긴게 json이라면)=> javascript 오브젝트로 변경
})
.done(function (resp) {
alert("회원가입이 완료되었습니다.");
//console.log(resp);
location.href = "/";
})
.fail(function (error) {
alert(JSON.stringify(error));
});
출처:
https://www.youtube.com/watch?v=jQhzL1nkk2s
id="execute" 를 클릭하면 발동한다.
let index = {
init: function () {
$("#btn-save").on("click", () => {
//()=>{} this를 바인딩하기 위해서!
this.save();
});
$("#btn-update").on("click", () => {
//()=>{} this를 바인딩하기 위해서!
this.update();
});
// $("#btn-login").on("click", () => {
// //()=>{} this를 바인딩하기 위해서!
// this.login();
// });
},
내가 사용중인 예제와 비교 중
31행 data에서 14행 23행 form값 가져온다.
이렇게
JSON처리법
8행 dataType이 중요하다. json타입이라고 명시.
JSON데이터 출력중이다.
내가 사용중인 예제와 조금 다른 형태이다.
728x90
'자바스크립트' 카테고리의 다른 글
JS[JavaScript] 이전 페이지로 돌아가기, History.Back(), History().Go() (0) | 2022.02.22 |
---|---|
select 태그 안에 직접입력 만들기 (0) | 2022.02.04 |
자바스크립트 공부중 (0) | 2022.01.31 |
자바스크립트 자주 사용하는 함수 (0) | 2021.12.22 |
자바스크립트 공부 (0) | 2021.12.22 |
댓글