2011-02-25 3 views
0

내 javascript/ajax 코드는 처음에는 작동하지만 이후에는 작동하지 않습니다. 함수가 다시 호출 될 때 GetAttribute 요소는 null입니다. createElement와 AppendChild를 사용해 보았지만 똑같은 일을합니다. getAttribute가 필요 없으면 제대로 작동하지만 getAttribute 메소드로 작동하는 함수를 가져올 수 없습니다. 어떤 도움을 주시면 감사하겠습니다.Ajax 통화는 처음으로 작동합니다.

function ajaxFunction(Picked) { 
var getdate = new Date(); 
if(xmlhttp) { 
    var Pic1 = document.getElementById("Pic1").getAttribute("name"); 
    var Pic2 = document.getElementById("Pic2").getAttribute("name"); 
    if (Picked === Pic1){ 
    var Chosen = Pic1; 
    var NotChosen = Pic2; 
} 
else { 
    var Chosen = Pic2; 
    var NotChosen = Pic1; 
} 
    xmlhttp.open("POST","choice.php",true); 
    xmlhttp.onreadystatechange = handleServerResponse; 
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    xmlhttp.send("Chosen=" + Chosen + "&NotChosen=" + NotChosen); 
    } 
} 

function handleServerResponse() { 
    if (xmlhttp.readyState == 4) { 
    if(xmlhttp.status == 200) { 
     var response = xmlhttp.responseText; 
     response = response.split("|"); 
     document.getElementById('Pic1').innerHTML = response[0];//New Pic 
     document.getElementById('Pic2').innerHTML = response[1];   
    } 
    else { 
    alert("Error. Please try again"); 
    } 
} 
} 
+0

프레임 워크/라이브러리를 사용하지 않는 이유가 있습니까? –

+0

취미, 방금 나 자신과 친구를 위해 프로그램. jquery 등의 내용을 배우기 위해 앉지 않았다 – user634510

답변

1
if if (Picked = Pic1)를 작성하여

if (Picked === Pic1) 

에, 당신은 Pic1Picked를 할당있어 변경

.

+0

미안하지만, 여전히 사진의 이름을 얻을 수 없다. – user634510

관련 문제