亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jqery ajax issue - Stack Overflow
phpcn_u1582
phpcn_u1582 2017-07-05 10:48:17
0
1
812

My question is this

When you click the "Continue Adding" link after 5 items are displayed, click once to add the specified amount of data until the data in the json file is fetched
That is, after 5 items are displayed, click for the first time , displays 6, 7, 8, the second time displays 9, 10, 11, and so on. Is there any way to solve it? My code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
    <title>測(cè)試</title>
    <script src="../web/js/jquery-3.2.1.min.js"></script>
    <script src="text.json"type="application/json"></script>
</head>
<body>
<p id="btn">點(diǎn)擊</p>
<p id="json">

</p>
<a href="javascript:void(0)" class="clicks" style="display: none">繼續(xù)添加</a>
<p class="num"></p>
<p class="ccc"></p>
<script>
    $(document).ready(function () {

        $('#btn').click(function () {
            var json=$('#json');
            var num=0;
            var p=$('p');
            json.append('<p class="json"></p>')
            $.ajax({
                type:'post',
                url:'text.json',
                data:null,
                dataType:'json',
                success:function (ress) {
                    var str;
                    str='';
                    $.each(ress,function (index,res) {
                        if(num<5){
                            str+='<p class="lens"><span>名稱:'+res['tip']+'</span></br>';
                            str+='<span>作者:'+res['author']+'</span></br></p>';

                            $('.clicks').css({
                                display:'block'
                            })
                            $('.num').html('已加載了'+(num+1)+'條數(shù)據(jù)....');
                        }

                        json.html(str);
                        num++;



                    });
                    var count=0;
                    $.each(ress,function (index,res) {
                        if(index>4){
                            $('.clicks:last').click(function () {
                                if(count<3){
                                    str= '<p class="lens"><span>'+res['tip']+'</span></br>' +
                                        '<span>'+res['author']+'</span></br></p>'
                                    $('#json').append(
                                        str
                                    )
                                }
                                count++
                            });
                        }
                    })

                    var str1;
                    str1=ress.length-$('.lens').length;
                    $('.ccc').html('還有'+(str1-1)+'條數(shù)據(jù)');

                },
                error:function (res) {
                    console.log(res)
                }
            })

        })
    })
</script>
<style>
    .lens{border-bottom: 2px solid red}
</style>
</body>
</html>
phpcn_u1582
phpcn_u1582

reply all(1)
我想大聲告訴你

For the first request, store the returned data in an array. You can just operate this array the next time you click. There is no need to request again

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template