2009-08-22 3 views
0

내 자바 스크립트 코드로 내 PHP를 호출하는 데 문제가 있습니다. 누구든지 다음 코드에서 오류가 표시됩니까? 나는이 사이트의 다른 부분에서 다음과 같이 코드를 사용하고있다.기본 xml HTTP 질문

var xmlHttp = createXmlHttpRequestObject(); 
var favSongArray = []; 

function createXmlHttpRequestObject(){ 
    var xmlHttp; 

    try{ 
    xmlHttp = new XMLHttpRequest(); 
    } 
    catch(e){ 
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", 
           "MSXML2.XMLHTTP.5.0", 
           "MSXML2.XMLHTTP.4.0", 
           "MSXML2.XMLHTTP.3.0", 
           "MSXML2.XMLHTTP", 
           "Microsoft.XMLHTTP"); 

    for(var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++){ 
    try{ 
     xmlHttp = new ActiveXObject(XmlHttpVersions[i]); 
    } 
    catch(e){} 
    } 
} 

if(!xmlHttp){ 
    alert("Error creating the XMLHttpRequest object."); 
} 
else{ 
    return xmlHttp; 
} 
} 


function process(){ 

    if(xmlHttp){ 
    alert("sever is available"); 
    //if yes try 
    try{ 

     xmlHttp.open("GET", "php/getUntimed.php", true); 
     xmlHttp.onreadystatechange = function(){handleRequestStateChange();}; 
     alert("attempted to call p_handleRequestStateChange_test"); 
     xmlHttp.send(null); 
    }//end try 
    catch(e){ 
     alert("Can't connect to server: \n" + e.toString()); 
    }//end catch 
    }//end if xmlHHttp 

}//end function 

function handleRequestStateChange(){ 
    if(xmlHttp.readyState == 4){ 

    if(xmlHttp.status == 200){ 
    try{ 
    u_handleServerResponse(); 
    }//end try 
    catch(e){ 
    alert("Error reading the response: " +e.toString()); 
    }//end catch 
}//end if 
else{ 
    alert("There was a problem retriving the data:\n" + xmlHttp.statusText); 
}//end else 
}//end if 
}//end function 

function u_handleServerResponse(){ 
//need to clear array each time 
var response = xmlHttp.responseText; 

favSongArray = response.split("+"); 
alert("made it here"); 
//getFlashMovie("trackTimer").trackTimer(favSongArray[0]); 
} 

onSubmit 트리거에서 process()가 호출된다. 나는 0의 xmlHttp.status를 계속 얻는다. 누구에게도 의미가 있습니까? 감사합니다

+0

Firebug를 실행하고 있습니까? 서버가 요청을 받고 있습니까? –

+0

방화범이 끌리는 곳은 어디입니까? – danwoods

+0

넷 또는 콘솔 탭에 있습니다. –

답변

0

왜 아약스 프레임 워크를 사용해 보지 않으시겠습니까? 예를 들어 jQuery과 같습니다.

3

status == 0 보통이 중단 된 수단 - 하나 ESC을 누르거나 현재 어드레스를 변화시킴으로써.

또는, 글로벌 xmlHttp을 사용하고 있기 때문에, 당신은 open 및/또는 마지막 요청을 완료 할 시간이되기 전에 send를 호출 할 수있다. 어느 것이 확실하지는 않지만 어느 하나가 abort으로 전화를 시작합니다.

1

Jonathan Lonowski says으로 status == 0 중단을 의미합니다, 당신은 당신이 따라서, 제출 양식을 실행할 것이라고 스크립트 onsubmit를 실행 페이지를 다시로드하고, Ajax 요청을 중단했다. 보세요 here 너무보세요.

+0

감사합니다. 페이지를 다시로드하는 것이 어떻게 든 엉망이라고 생각했습니다. – danwoods