我有一个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>
..
这个过程应该是这样的:
<代码>G211
发布于 2011-07-04 18:28:49
<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>
发布于 2011-06-28 21:09:47
通过使用jQuery注册锚点的单击事件(使用class="movie")并使用.load()
方法发送AJAX请求并替换摘要div的内容,可以非常容易地实现这一点:
$(function() {
$('.movie').click(function() {
$('#summary').load(this.href);
// it's important to return false from the click
// handler in order to cancel the default action
// of the link which is to redirect to the url and
// execute the AJAX request
return false;
});
});
发布于 2013-03-07 13:46:05
尝尝这个
function getmoviename(id)
{
var p_url= yoururl from where you get movie name,
jQuery.ajax({
type: "GET",
url: p_url,
data: "id=" + id,
success: function(data) {
$('#summary').html(data);
}
});
}
而你的html部分是
<a href="javascript:void(0);" class="movie" onclick="getmoviename(youridvariable)">
Name of movie</a>
<div id="summary">Here is summary of movie</div>
https://stackoverflow.com/questions/6506873
复制相似问题