我有一个div,其中包含数据库的一些文本:
<div id="summary">Here is summary of movie</div>
和链接列表:
<a href="?id=1" class="movie">Name of movie</a> <a href="?id=2" class="movie">Name of movie</a> ..
这个过程应该是这样的:
>点击链接
> Ajax使用链接的URL将数据通过GET传递到PHP文件/同一页面
> PHP返回字符串
> div更改为此字符串
<script> function getSummary(id) { $.ajax({ type: "GET",url: 'Your URL',data: "id=" + id,// appears as $_GET['id'] @ your backend side success: function(data) { // data is ur summary $('#summary').html(data); } }); } </script>
并在列表中添加onclick事件
<a onclick="getSummary('1')">View Text</a> <div id="#summary">This text will be replaced when the onclick event (link is clicked) is triggered.</div>