我是Ajax
,Jquery
&的新手PHP
。
我被困在代码中我希望有人可以指导我解决问题:
<script type="text/javascript">
$(document).ready(function(){
$('#number_filters a').bind("click", function() {
var year = $(this).attr('href');
$.post('getdata.php',{resultyear:year},function(res){
$("#showresult").html(res);
});
return false;
});
});
</script>
Following code, if anyone click on link below, I am send a value by POST method to a php page and the returned data are displayed in DIV Tag:
<div id="number_filters">
<a href="1" class="c1">Link 1</a>
<a href="2" class="c1">Link 2</a>
</div>
this is the div tag I use to display results from above code:
<div id="showresult"></div>
Up until now it has been working fine, and below is the output which I get from dynamic page:
Output: 2015 2014 2013 2012 2011
现在我的问题是,如果点击2015年或2014年我想再次显示动态数据检索数据库。
任何人都可以给我一些想法或代码,我可以尝试解决这个问题吗?
答案 0 :(得分:0)
修改生成输出的php文件中的输出,如:
$output = "<a href='2015'>2015</a> <a href='2014'>2014</a>";
使用以下代码更新您的jquery:
$('#showresult').on('click', 'a', function(){
var year = $(this).attr('href');
// Ajax Request
$.post(....);
});
.on()可帮助您实现自己想要的目标。