Javascript jqueryajax:刷新具有不同id的多个div';s

Javascript jqueryajax:刷新具有不同id的多个div';s,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我想刷新页面上多个项目的倒计时。每个计时器都有“刷新项”类。它只适用于一个项目,但如果我有多个项目(这意味着不同的倒计时),它似乎只选择最新的id 这是我的JQuery代码: function timeLeft() { var data = $(".refresh-item").attr("data-content"); var dataString = 'case=refresh_item&' + data; $.ajax({ type:

我想刷新页面上多个项目的倒计时。每个计时器都有“刷新项”类。它只适用于一个项目,但如果我有多个项目(这意味着不同的倒计时),它似乎只选择最新的id

这是我的JQuery代码:

function timeLeft()
{   
    var data = $(".refresh-item").attr("data-content"); 
    var dataString = 'case=refresh_item&' + data;

    $.ajax({
      type: "GET",
      url: "ajax.php",
      dataType: "html",
      data: dataString,
      success: function(result) 
        {   
          $(".refresh-item").html(result);
        }
    });
}

window.setInterval(function(){
    timeLeft();
}, 1000);

每个项目还具有“数据内容”属性,其中保存项目的特定id。如何选择特定项目的特定id(然后显示单个倒计时计时器)

使用$。jquery的每个函数:

function timeLeft()
{   
    $.each($(".refresh-item"), function(){
        $this = $(this);
        var data = $this.attr("data-content"); 
        var dataString = 'case=refresh_item&' + data;
         $.ajax({
          type: "GET",
          url: "ajax.php",
          dataType: "html",
          data: dataString,
          success: function(result) 
            {   
              $this.html(result);
            },
          complete: function(){}
    });
    )

}

window.setInterval(function(){
    timeLeft();
}, 1000);

使用$。jquery的每个函数:

function timeLeft()
{   
    $.each($(".refresh-item"), function(){
        $this = $(this);
        var data = $this.attr("data-content"); 
        var dataString = 'case=refresh_item&' + data;
         $.ajax({
          type: "GET",
          url: "ajax.php",
          dataType: "html",
          data: dataString,
          success: function(result) 
            {   
              $this.html(result);
            },
          complete: function(){}
    });
    )

}

window.setInterval(function(){
    timeLeft();
}, 1000);
在jQuery中使用方法进行迭代

function timeLeft() {
  $(".refresh-item").each(function() {
    $this = $(this);
    var data = $this.attr("data-content");
    var dataString = 'case=refresh_item&' + data;
    $.ajax({
      type: "GET",
      url: "ajax.php",
      dataType: "html",
      data: dataString,
      success: function(result) {
        $this.html(result);
      }
    });
  });
}

window.setInterval(function() {
  timeLeft();
}, 1000);
在jQuery中使用方法进行迭代

function timeLeft() {
  $(".refresh-item").each(function() {
    $this = $(this);
    var data = $this.attr("data-content");
    var dataString = 'case=refresh_item&' + data;
    $.ajax({
      type: "GET",
      url: "ajax.php",
      dataType: "html",
      data: dataString,
      success: function(result) {
        $this.html(result);
      }
    });
  });
}

window.setInterval(function() {
  timeLeft();
}, 1000);

您可以使用$(“.refresh item”)。每个()都可以使用$(“.refresh item”)。每个()都可以在ajax请求中的完整函数中调用下一个请求:complete:function(){}在ajax请求中的完整函数中调用下一个请求:complete:function(){}