ajaxを使用してページのdivをリロードすると機能しますが、スクリプトをリロードしようとすると機能しません。私のjavascriptはデータベースから動的であり、divも動的です。これが私のコードです:
<ul id="classes">
<?php
$email = 'thomas990428@me.com_classes';
$result = mysqli_query($con,"SELECT * FROM `$email` ORDER BY period"); if (!$result) echo mysqli_error(); else // ok, do your thing.
$classcount = 1;
while($row = mysqli_fetch_array($result))
{
$period = $row['period'];
$teacher = $row['teacher'];
$subject = $row['subject'];
$subjecto = strtolower($subject);
$subjecto = str_replace(' ', '', $subjecto);
$grade = $row['grade'];
echo "<li id='button" . $classcount . "' class='button' onclick='" . $subjecto . "(),homework" . $classcount . "()'><div class='deletebutton' onclick='deleteclass" . $subjecto . "()'>X</div><span class='course'>" . $classcount . ". " . $subject . "</span></li>\n";
$classcount += 1;
}
?>
<script>
<?php
$email = 'thomas990428@me.com_classes';
$result = mysqli_query($con,"SELECT * FROM `$email`");
while($row = mysqli_fetch_array($result))
{
$period = $row['period'];
$teacher = $row['teacher'];
$subject = $row['subject'];
$subjecto = strtolower($subject);
$subjecto = str_replace(' ', '', $subjecto);
$grade = $row['grade'];
echo "function deleteclass" . $subjecto . "() { \n";
echo "var hi = confirm('Are you absolutely sure you want to permantly delete this class? This cannot be undone.'); \n";
echo "if (hi==true) \n";
echo "{ \n";
echo "document.getElementById('hiddenframe').src='deleteclass.php?class=".$subjecto."';";
echo "closeedit();";
echo "refreshclasses();";
echo "} \n";
echo "else \n";
echo "{} \n";
echo "} \n";
}
?>
</script>
</ul>
<iframe id="hiddenframe"></iframe>
つまり、基本的にはulを更新しますが、スクリプトは更新しません。必要なことを行うために、両方を更新する必要があります。何か案は?ありがとう!