내 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");
}
}
}
프레임 워크/라이브러리를 사용하지 않는 이유가 있습니까? –
취미, 방금 나 자신과 친구를 위해 프로그램. jquery 등의 내용을 배우기 위해 앉지 않았다 – user634510