PHP重新加载内容
我试图在页面上实时更新内容,然后用户单击按钮 内容部分:PHP重新加载内容,php,Php,我试图在页面上实时更新内容,然后用户单击按钮 内容部分: <p class="chapterContent"><?php echo $chapterContent[$chapter]; ?></p> 这是我的按钮: <span class="navigationItem"><a href="" onclick= <?php $chapter = 0; ?>>1</a></span> <
<p class="chapterContent"><?php echo $chapterContent[$chapter]; ?></p>
这是我的按钮:
<span class="navigationItem"><a href="" onclick= <?php $chapter = 0; ?>>1</a></span>
<span class="navigationItem"><a href="" onclick= <?php $chapter = 1; ?>>2</a></span>
$chapterContent是具有不同字符串的数组。所以,用户单击1,它将加载$chapterContent[0],如果他单击2,它将加载$chapterContent[1]
我所拥有的东西不起作用,如何才能让class.chapterContent中的html代码用正确的章节重新加载?感谢您的帮助 你需要的是这样的东西
<p id="chapterContent"></p>
<span class="navigationItem"><a href="" onclick="return display_text('0');">1</a></span>
<span class="navigationItem"><a href="" onclick="return display_text('1');">2</a></span>
<script type="text/JavaScript">
<!--
function display_text( which )
{
$.post( "display.php", { which : which }, function( data ){ document.getElementById( "chapterContent" ).innerHTML = html = data }, "html" );
return false;
}
//-->
</script>
将其放入display.php文件中:
<?php echo $chapterContent[$_POST["which"]]; ?>
当然,您应该添加增加安全性的代码等等 您需要了解如何实现该目标。jQuery或任何其他AJAX方法。不要忽视你可以显示你的全部代码&错误是什么