다음의 Ajax 코드가 IE 에서 실행되지 않는 이유를 모르겠습니다.

vudghkzm의 이미지

아래는 실행되는 run.html 파일입니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple XMLHttpRequest</title>
 
<script type="text/javascript">
var xmlHttp;
 
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}  
 
function startRequest() {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    //xmlHttp.open("get", "simpleResponse.xml", true);
    xmlHttp.open("get", "t.php", true);
    xmlHttp.send(null);
}
 
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            alert("The server replied with: " + xmlHttp.responseText);
        }
    }
}
</script>
</head>
 
<body>
    <form action="#">
        <input type="button" value="Start Basic Asynchronous Request" onclick="startRequest();"/>
    </form>
</body>
</html>

아래는 t.php 파일의 내용입니다.

<?php
 
print 'aa';
 
?>

run.html 파일을 파이어폭스에서 실행하면 The server replied with: aa 라는 메세지가 올바로 출력이 됩니다만 IE 에서 실행하면 메세지가 출력되지 않고, IE 왼쪽 하단에 오류가 났다는 메세지가 나타납니다. 그리고 그 오류가 난 장소는 run.html 의 alert("The server replied with: " + xmlHttp.responseText); 부분이구요.

왜 이런 차이점이 생기는지 알고 싶습니다.

그리고 t.php 대신에 t.html 혹은 t.xml 파일을 만들고 내용은 그냥 텍스트로 aa 라고 하면 IE 에서도 잘되더라구요.
이건 또 왜 이런지 궁금합니다.

평양선봉의 이미지

xmlHttp.send(null); 전에

xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

부분을 추가하셔서.. charset을 UTF-8로.. 설정하시고

받는 t.php 상단에..

Header("Content-type: text/css; charset=UTF-8");

라고 설정해 보시기 바랍니다...

"-1072896658 오류.."라고 나게 되면.. 제가 알고 있기로는 IE의 UTF-8 처리 버그라고 알고 있습니다.

----
웹페이지 : http://bzpalm.net/