weixin_33724046 2018-07-19 13:05 采纳率: 0%
浏览 36

AJAX请求超时

I did ajax get request on php file that takes temperature data via snmp and give back a json array of data.

Now for every location I'm trying to generate only once the divs and then only update the values.

Treid to do on the first ajax request to generate the divs with the values inside already to an array and then display them but they won't display in the specific div.

I can see in the console that the array is properly populated. But I can't make it display all the elements in the div with id=data. Tried html(), append(), text() and nothing works.

How should I modify the code so the request won't take that much time?

I'm thinking of creating containers for every location temperature once with the first ajax request and then using setIntervals only getting the value and updating it so I guess it won't take that much time on the request and I will avoid page flickering cause only the numbers will change but how can I achieve that?

I don't want to reload the page.

      $(document).ready(function(){

          var tr_str = [];
          var menu_list = [];

          $.ajax({
              url: 'getData.php',
              type: 'get',
              dataType: 'JSON',
              success: function(response){
                  var len = response.length;
                  for(var i=0; i<len; i++){
                      var location = response[i].location;
                      var temp_int = response[i].temp_int;
                      var temp = response[i].temp;
                      var hum = response[i].hum;
                      var dew = response[i].dew;

                      tr_str[i] = "<div id='locc" + i + "' class='location'>" +
                          "<span class='title'>" + location + "</span>" +
                          "<div class='temp'" + i + "><span>Temperatura: </span><span id='check'>" + temp + " &degC</span></div>" +
                          "<div><span>Względna wilgotność: </span><span>" + hum + " %RH</span></div>" +
                          "<div><span>Punkt rosy: </span><span>" + dew + " &degC</span></div>" +
                          "</div>";

                      menu_list[i] = "<label for='loc" + i + "'>" +
                          "<input type='checkbox' id='loc" + i + "' />" +
                          "<span class='css-checkbox'></span>" +
                          "<p>" + location + "</p>" +
                          "</label>";
                  }

              },

          });


          console.log(tr_str);
          console.log(menu_list);


            $("#data").html(tr_str[0]);

<!-- language: lang-html -->

    <body>
    <div id="data" class="wrapper"></div>
    </body>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序