???? ?? ?? ?? ?? ??? ?? PHP ??(3)
jQuery? ?? ? ?? ??? ?????. ??? Ajax? ?? ?????? ?? ??? ?? ???? ????. ?? ??? ???? ?? ???? ???? ?? ??? ???? ?? 1? ??? ????.
?? ???? ??? ? $.ajax()? ?? ????? filelist.php? GET ??? Ajax ??? ????. filelist.php? ????? ???? ??? json ???? ???? $.each? ?? ?????. () json ??? ??? ????, html ???? ????, ?? ???? ul.filelist? ???? ???? ?? ??? ?????.
?? ??? ???? ?????? ???? ??? ?? ??? ?? ???? live()? ?? ???? ???? ??? ?????.
<script type="text/javascript"> $(function(){ $.ajax({ //異步請求 type: 'GET', url: 'filelist.php', dataType: 'json', cache: false, beforeSend: function(){ $(".filelist").html("<li class='load'>正在載入...</li>"); }, success: function(json){ if(json){ var li = ''; $.each(json,function(index,array){ li = li + '<li><a href="download.php?id='+array['id']+'">'+array['file']+'<span class="downcount" title="下載次數(shù)">' +array['downloads']+'</span><span class="download">點擊下載</span></a></li>'; }); $(".filelist").html(li); } } }); $('ul.filelist a').live('click',function(){ var count = $('.downcount',this); count.text(parseInt(count.text())+1); }); }); </script>
Notes:
ajax? ??? ????
1.type
Type: String
???: "GET"). ?? ??("POST" ?? "GET"), ???? "GET"???.
2.url
??: ???
???: ?? ??? ??. ??? ?? ?????.
3.dataType
Type: String
???? ??? ??? ???? ??? ?????. ??? "json"???. JSON ???? ?????.
4.cache
??: Boolean
???: true, dataType? script?? jsonp? ?? ???? false???. ? ???? ???? ???? false? ?????.
5.beforeSend
Type: Function
??? ??? ?? XMLHttpRequest ??? ??? ? ?? ?????.
XMLHttpRequest ??? ??? ???????.
6.success
Type: Function
?? ?? ? ?? ?????.
live() ???? ?? ??? ??? ???? ??? ??? ???? ??? ???? ??? ? ??? ??? ?????.
?? ? ?? ?? ?? ??? ??? ????? ???? Ajax ?????. ?? ????? ???? ?? PHP? ??? ??? ????.
jQuery ? ajax ??? ? ??? ??? ipnx.cn?? ?? ????? ?????.