2012-01-19 1 views
0

다음 코드에 문제가 있습니다. IE8에서 실행하면 호출이 성공적으로 반환 될 때 경고 메시지가 나타납니다.Firefox 및 Chrome에서 Ajax POST 문제 (IE8 제외)

Firefox 및 Chrome에서는 이러한 일이 발생하지 않습니다. 즉, Firefox 및 Chrome에서는 실행되지 않습니다. 즉, 실행시 알림 메시지가 표시되지 않습니다. 다른 모든 것은 작동합니다. 단, 호출이 성공하면 실행해야하는 코드 섹션이 마음에들 것 같습니다.

function stuffFile(file, wfid) { 

    var xmlhttp = new XMLHttpRequest(); 

    if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari 
      xmlhttp = new XMLHttpRequest(); 
     } else {// code for IE6, IE5 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     } 

    var url = "http://someotherserver.page.aspx"; 
    var params = "fileName=" + file + "&param11=" + wfid; 
    xmlhttp.open("POST", url, true); 

    //Send the proper header information along with the request 
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    xmlhttp.setRequestHeader("Content-length", params.length); 
    xmlhttp.setRequestHeader("Connection", "close"); 

    xmlhttp.onreadystatechange = function() {//Call a function when the state changes. 
     //alert('onready'); 
     if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
      var response = jQuery.trim(xmlhttp.responseText); 
      alert('response ' + response); 
     } 
    } 
    xmlhttp.send(params); 


} 
+0

크롬에서 작동합니다. http://jsfiddle.net/wGeAY/ (url/params가 변경되었습니다.) 당신은 분명히 당신의 스택에 jQuery를 가지고 있는데, 왜 간단한 ajax 기능을 사용하지 않을까요? –

+0

콘솔로 디버깅 해 보셨습니까? – j08691

+0

문제는 URL이 다른 도메인에 있다는 것입니다. Firefox는 허용하지 않습니다. – oneiros

답변

1

이미 jQuery를 사용하고 있으므로 AJAX 기능을 사용해야합니다. XMLHTTPRequest 개체와 다른 브라우저 간의 모든 차이점을 처리하고 수동으로 수행하는 많은 작업을 수행합니다.

관련 문제