[英]Get value from dynamic href using jquery ajax php
我是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,我想再次显示动态数据检索数据库。
谁能给我一些想法或代码,我可以尝试解决这个问题?
修改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()可帮助您实现所需的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.