[英]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.