要刷新的Javascript拉动保留LastID变量

问题描述 投票:0回答:1

学习,所以请客气,而不是专业的编码员!使用PHP可以,但是使用Javascript我是完全的新手。

tl; dr我如何保留last id中的JSON变量以停止我的AJAX拉取其已具有的内容?

[尝试进行“拉动以刷新”工作,它正在运行,但我被卡住了。我有mysql/php/ajax罚款。我可以拉下来,它会更新。但是它将继续添加现有内容。

我研究了使用letvarnothingwindow.variable以不同方式分配变量的方法。如果有区别,请使用Framework7

今天是页面,highid是JSON中返回的最高ID号。调用get时,会将highid赋予mysql以获取最新的信息。 PHP / JSON / AJAX部分有效。但是找不到下一次设置变量的方法。

var html = '';

// Pull to refresh on Today tab
$$('.ptr-content').on('ptr:refresh', function (e) {

  setTimeout(function () {


 if (typeof today_highid === 'undefined') {
      var today_highid = 5;
    }
    app.request.json('/__php/json1.php', { article_id: today_highid }, function (data) {

      for(var i = 0; i < data['article'].length; i+=1){

         html+=
            '<div class="title-container">'+
            '<span class="title-date">Tuesday 19 March</span>'+
            '<h1>' +data['article'][i]['article_title']+ '</h1>'+
            '</div>'+
            '<a href="/single/">'+
            '<div class="card">'+
            '<img class="card-image" src="img/thumb-14.jpg" alt="">'+
            '<div class="card-infos">'+
            '<h2 class="card-title">' +data['article'][i]['article_content']+ '</h2>'+
            '<div class="card-bottom">'+
            '<div class="card-author">'+
            '<img class="card-author-image" src="img/authors/author-1.jpg" alt="">'+
            '<div>Camille Aline</div>'+
            '</div>'+
            '<div class="card-comments"><i class="f7-icons">chat_bubble_fill</i></i>' +today_highid+ '</div>'+
            '</div>'+
            '</div>'+
            '</div>'+
            '</a>';


      }
      //$$('.data-table table').html(tableHtml);
      // Prepend new list element
      $$('.ptr-content').find('#today-content').prepend(html);

      window.today_highid = data['status']['highid'];


    });

感谢您的任何帮助,也请指向一个有效的教程,谢谢!! >>

学习,所以请客气,而不是专业的编码员!使用PHP可以,但是使用Javascript我是完全新手。 tl; dr如何保留JSON中的最后一个id变量以停止我的AJAX提取内容...

javascript ajax html-framework-7 pull-to-refresh
1个回答
0
投票

问题是您拥有window.today_highid = data['status']['highid'];,但在函数内部将其设置为var today_highid = 5。哪个不一样。 today_highidwindow的属性。同样,当您实际使用它{ article_id: today_highid }时,您只是在功能范围内引用var。不是window .today_highid`的值。

© www.soinside.com 2019 - 2024. All rights reserved.