Jquery刷新多个变量

Jquery刷新多个变量,jquery,ajax,refresh,Jquery,Ajax,Refresh,我很难找到好的资源或任何关于如何实现以下目标的想法: 使用jquery获取一些数据。现在,数据应该使用什么语法。转至步骤2 再次使用jquery,将该数据分配给html页面上的多个变量和标记。我知道如何更换1个标签。但我想刷新多个div,tag,id。转至步骤3 过一段时间后,现在回到步骤1 我试过我的朋友谷歌,但它找不到我要找的页面。我非常感谢这里的一些代码,但是到教程的链接也不会太糟糕。1-请参阅和相关的高级包装,例如,和 2-如果您的服务器向客户机发送JSON,而客户机了解如何使用它,那么

我很难找到好的资源或任何关于如何实现以下目标的想法:

  • 使用jquery获取一些数据。现在,数据应该使用什么语法。转至步骤2
  • 再次使用jquery,将该数据分配给html页面上的多个变量和标记。我知道如何更换1个标签。但我想刷新多个div,tag,id。转至步骤3
  • 过一段时间后,现在回到步骤1
  • 我试过我的朋友谷歌,但它找不到我要找的页面。我非常感谢这里的一些代码,但是到教程的链接也不会太糟糕。

    1-请参阅和相关的高级包装,例如,和

    2-如果您的服务器向客户机发送JSON,而客户机了解如何使用它,那么这是微不足道的。e、 g:

    // json from server
    { "newsDiv" : "some html", "imagesDiv", "some html" }
    
    // assuming it is stored in the variable 'data'
    $("#newsDiv").html(data.newsDiv);
    $("#imagesDiv").html(data.imagesDiv");
    
    3-是您的朋友。

    1-请参阅和相关的高级包装,例如,和

    2-如果您的服务器向客户机发送JSON,而客户机了解如何使用它,那么这是微不足道的。e、 g:

    // json from server
    { "newsDiv" : "some html", "imagesDiv", "some html" }
    
    // assuming it is stored in the variable 'data'
    $("#newsDiv").html(data.newsDiv);
    $("#imagesDiv").html(data.imagesDiv");
    

    3-是您的朋友。

    然后查看jquery的“加载”功能。这样,您就可以从服务器加载数据并将其放入匹配的html元素中。非常干净简单。 然后,看看如何实现计时器


    我看不出您还需要什么

    然后查看jquery“加载”函数。这样,您就可以从服务器加载数据并将其放入匹配的html元素中。非常干净简单。 然后,看看如何实现计时器

    我看不出您还需要什么。

    1)
    $。ajax()
    似乎是个好主意,用它来获取JSON格式的数据:

    $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: callback //Assign data and stuff here
    });
    
    2) 在
    success
    -参数中作为新函数执行此操作<代码>成功:函数(){}

    success: function() {
        $('div#1').html('foo');
        $('h1#1').html('woo');
    }
    
    3) 将您的
    $.ajax()
    -以一定间隔调用:

    var refresh = setInterval(function()
    $.ajax({
          url: url,
          dataType: 'json',
          data: data,
          success: callback //Assign data and stuff here
         });
     }, 60000);
    
    编辑(对以下评论的回应):

    请尝试以下方法,因为您没有将函数()用作回调:

    function() { 
        $.ajax({ 
            url: "/admin/ajax/all_data.php", 
            dataType: 'json', 
            data: data, 
            success: function(data) {
                $("#testdiv1").html(data.testdiv1); 
                //$("#testdiv2").html(data.testdiv2); 
                //$("#testdiv3").html(data.testdiv3); 
            }
        }); 
    }), 2000);
    
    让我知道这是否适合您。

    1)
    $.ajax()似乎是个好主意,使用它来获取JSON格式的数据:

    $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: callback //Assign data and stuff here
    });
    
    2) 在
    success
    -参数中作为新函数执行此操作<代码>成功:函数(){}

    success: function() {
        $('div#1').html('foo');
        $('h1#1').html('woo');
    }
    
    3) 将您的
    $.ajax()
    -以一定间隔调用:

    var refresh = setInterval(function()
    $.ajax({
          url: url,
          dataType: 'json',
          data: data,
          success: callback //Assign data and stuff here
         });
     }, 60000);
    
    编辑(对以下评论的回应):

    请尝试以下方法,因为您没有将函数()用作回调:

    function() { 
        $.ajax({ 
            url: "/admin/ajax/all_data.php", 
            dataType: 'json', 
            data: data, 
            success: function(data) {
                $("#testdiv1").html(data.testdiv1); 
                //$("#testdiv2").html(data.testdiv2); 
                //$("#testdiv3").html(data.testdiv3); 
            }
        }); 
    }), 2000);
    

    让我知道这是否适合您。

    Ahh,在我的列表中使用点刺会破坏代码框。修复了这似乎不起作用…function(){$.ajax({url:/admin/ajax/all_data.php),数据类型:'json',数据:data,success:$(“#testdiv1”).html(data.testdiv1);/$(“#testdiv2”).html(data.testdiv2)//$(“#testdiv3”).html(data.testdiv3);});},2000年)@user658911我更新了上面的帖子,向您展示了如何编写回调。没问题,很高兴我能提供帮助!:-)啊,在我的名单上打了一个点号,使密码箱瘫痪了。修复了这似乎不起作用…function(){$.ajax({url:/admin/ajax/all_data.php),数据类型:'json',数据:data,success:$(“#testdiv1”).html(data.testdiv1);/$(“#testdiv2”).html(data.testdiv2)//$(“#testdiv3”).html(data.testdiv3);});},2000年)@user658911我更新了上面的帖子,向您展示了如何编写回调。没问题,很高兴我能提供帮助!:-)