2013-12-16 44 views
0

我是0123PO的新手,Jquery & PHP。 我被困在代码中,我希望有人能指导我解决这个问题:使用jquery ajax从动态href中获取值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

修改输出你产生像输出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()可以帮助你实现你想要的。

+0

嗨Jogesh,让我试试这个PLZ .... – user3106824

+0

你好Jogesh,谢谢你Sooooooooooooooo很多提供良好的逻辑,上帝保佑你我亲爱的.... – user3106824

+0

@ user3106824高兴地帮助你:),节日快乐 –