javascript 함수에 다른 변수를 전달하는 데 문제가 있습니다. 여기에 간다 :PHP MySQL AJAX - 동적 필드
나는 기본적으로 데이터 행을 빌드하는 PHP 코드를 가지고있다. 내가하고 싶은 일은 AJAX 호출을 통해 각 행을 개별적으로 저장하는 것입니다. 여기 내가 지금까지 가지고있는 것이있다. 무슨 일이 일어나고 첫 번째 행을 잘 작동하지만 모든 후속 행을 않습니다 (javascript 변수를 첫 번째 행에서 것입니다).
프런트 엔드 PHP 코드
<?php
$result = mysql_query("SELECT * FROM scoresheet WHERE matchup_id = '$matchupid' AND team_id = '$teama' AND status = '1' ");
$num_rows = mysql_num_rows($result);
if (mysql_num_rows($result) == 0) { echo "<div style='float:left;clear:both;'>Nothing found</div>"; } else {
while($row = mysql_fetch_array($result))
{
echo " <form name='input'>";
echo " <div class='tablecell'>".$row['full_name']."</div>";
echo " <div class='tablecell'>".$row['scoresheet_id']."</div>";
echo " <input type='hidden' id='scoresheet_id' name='scoresheet_id' value='".$row['scoresheet_id']."'></input>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='presenta' name='presenta' value='".$row['present']."'></input></div>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='sparea' name='sparea' value='".$row['spare']."'></input></div>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='goaliea' name='goaliea' value='".$row['goalie']."'></input></div>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='goalsa' name='goalsa' value='".$row['goals']."'></input></div>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='assistsa' name='assistsa' value='".$row['assists']."'></input></div>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='yellowa' name='yellowa' value='".$row['yellow']."'></input></div>";
echo " <div class='labelAnswer'><input class='standardscore' type='textfield' id='reda' name='reda' value='".$row['red']."'></input></div>";
echo " <input type='button' class='btnInput' style='float:left;margin-top:-2px;' onClick='updatescore()' value='Save'></input>";
}
}
?>
자바 스크립트 코드
function updatescore() {
var presenta = document.getElementById('presenta').value;
var sparea = document.getElementById('sparea').value;
var goaliea = document.getElementById('goaliea').value;
var scoresheet_id = document.getElementById('scoresheet_id').value;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtuser").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "testajax-x.php?presenta="+presenta+"&sparea="+sparea+"&goaliea="+goaliea+"&scoresheet_id="+scoresheet_id, true);
xmlhttp.send();
}
PHP에서 큰 따옴표를 사용하지 마십시오. http://stackoverflow.com/questions/482202/is-there-a-performance-benefit-single-quote-vs-double-quote-in-php – bokan