검색결과 리스트
SCRIPT/AJAX에 해당되는 글 1건
- 2010/05/31 ajax POST전송시 인코딩 문제!!!!
글
GET방식으로 전송시에는 상관없지만
POST방식으로 전송시 인코딩이 정말 중요하다!!EUC-KR 은 깨진다.. 왜냐하면 UTF-8전송이기 때문이다
POST방식으로 전송시 인코딩이 정말 중요하다!!EUC-KR 은 깨진다.. 왜냐하면 UTF-8전송이기 때문이다
아래 예를 우선 보자!!!
request = new createRequest();
var url = "../staff/staff_add_update.php";
var poststring = "";
var phonenum = $('hp1').value + "-" + $('hp2').value + "-" + $('hp3').value; //휴대폰번호
poststring = "pass1=" + encodeURI($('pwd').value);// utf형식으로 변형
poststring += "&phonenum=" + encodeURI(phonenum);
poststring += "&zip1=" + encodeURI($('zip1').value);
poststring += "&zip2=" + encodeURI($('zip2').value);
poststring += "&juso1=" + encodeURI($('juso1').value);
poststring += "&juso2=" + encodeURI($('juso2').value);
poststring += "&staff_id=" + encodeURI($('staff_id').value);
request.onreadystatechange = returnstaff_update;
request.open("POST",url,true);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");//헤더값 설정함
request.setRequestHeader("ajax", "true");
request.send(poststring);
보면 해더값을 설정하여 UTF-8전송을 하였다.. 그리고 그전에 encodeURI를 통해 인코딩한다!!
이럼 안깨진다^^ 하지만 POST를 받는 페이지가 만약 EUC-KR이라면??
당연히 깨진다!! 왜냐하면 UTF-8로 보내지 않았는가?ㅎㅎ 그문제는 정말 간단히 해결 할수 있다!!
php 에서는 iconv()라는 함수를 이용하여 간단히 인코딩을 변경 가능 하다^^
사용 법은 ...
request = new createRequest();
var url = "../staff/staff_add_update.php";
var poststring = "";
var phonenum = $('hp1').value + "-" + $('hp2').value + "-" + $('hp3').value; //휴대폰번호
poststring = "pass1=" + encodeURI($('pwd').value);// utf형식으로 변형
poststring += "&phonenum=" + encodeURI(phonenum);
poststring += "&zip1=" + encodeURI($('zip1').value);
poststring += "&zip2=" + encodeURI($('zip2').value);
poststring += "&juso1=" + encodeURI($('juso1').value);
poststring += "&juso2=" + encodeURI($('juso2').value);
poststring += "&staff_id=" + encodeURI($('staff_id').value);
request.onreadystatechange = returnstaff_update;
request.open("POST",url,true);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");//헤더값 설정함
request.setRequestHeader("ajax", "true");
request.send(poststring);
보면 해더값을 설정하여 UTF-8전송을 하였다.. 그리고 그전에 encodeURI를 통해 인코딩한다!!
이럼 안깨진다^^ 하지만 POST를 받는 페이지가 만약 EUC-KR이라면??
당연히 깨진다!! 왜냐하면 UTF-8로 보내지 않았는가?ㅎㅎ 그문제는 정말 간단히 해결 할수 있다!!
php 에서는 iconv()라는 함수를 이용하여 간단히 인코딩을 변경 가능 하다^^
사용 법은 ...
iconv("현재 언어","인코딩될 언어",인코딩할 string 또는 변수);
'SCRIPT > AJAX' 카테고리의 다른 글
| ajax POST전송시 인코딩 문제!!!! (0) | 2010/05/31 |
|---|
RECENT COMMENT