当我使用 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 而不是脚本。我需要它来刷新两者,以便做我需要它做的事情。有任何想法吗?谢谢!