결론부터 말하자면 form submit 방식으로는 한계가 있다!
html이 지원을 하지 않기 때문이다.(content type이 application/json인 상태로 post request를 날릴 수 없다! 뭔가 간단한 설정을 해주면 request header를 바꿀 수 있을 것 같지만 방법은 없다!)
따라서 결국은 ajax를 사용할 수 밖에 없다.
다음과 같은 jQuery ajax를 사용하면 json 방식의 post 요청을 간단하게 날릴 수 있다!
$.ajax({
type: "POST",
url: "http://www.test.com/test.jsp", // 요청할 주소
data: {"name": "James"}, // 여기에 json을 넣어주면 된다!
dataType: "json",
contentType : "application/json",
success: function(){}
});
html이 지원을 하지 않기 때문이다.(content type이 application/json인 상태로 post request를 날릴 수 없다! 뭔가 간단한 설정을 해주면 request header를 바꿀 수 있을 것 같지만 방법은 없다!)
따라서 결국은 ajax를 사용할 수 밖에 없다.
다음과 같은 jQuery ajax를 사용하면 json 방식의 post 요청을 간단하게 날릴 수 있다!
$.ajax({
type: "POST",
url: "http://www.test.com/test.jsp", // 요청할 주소
data: {"name": "James"}, // 여기에 json을 넣어주면 된다!
dataType: "json",
contentType : "application/json",
success: function(){}
});
'IT노트(구) > JavaScript' 카테고리의 다른 글
자바스크립트로 input type=text disable하기 (0) | 2015.12.03 |
---|---|
자바스크립트에서 특정 문자열 포함 개수 추출하기 (0) | 2015.12.01 |
자바스크립트 toFixed(), toPrecision()은 string을 리턴한다. (2) | 2015.11.17 |
자바스크립트 소수점 관련 유용한 함수 - toFixed() (0) | 2015.11.17 |
자바스크립트에서 날짜 및 시간 추출하는 방법 (0) | 2015.11.14 |