티스토리 뷰

반응형

이걸로 많은 시간을 소비해서 기록으로 남겨둡니다.

인터벌을 주고 싶을때.... 일정시간동안 계속 저장하고 싶을때?

5초 후 계속해서 자료를 계속 불러옴...

// 10초마다 updatetime 체크 및 함수 실행
var intervalId = setInterval(function () {
  var num = $("#num").val();
  $.ajax({
    url: "load_data.php?num=" + num,
    type: "post",
    data: "",
    success: function (data) {
      var parsedData = JSON.parse(data);
      console.log('현재 저장 시간 ' + parsedData.updatetime);

      // 이전 데이터와 현재 데이터 비교
      if (previousData !== null && JSON.stringify(parsedData) === JSON.stringify(previousData)) {
        return; // 데이터가 변경되지 않았으므로 업데이트하지 않음
      }

      previousData = parsedData; // 현재 데이터를 이전 데이터로 저장

      reload(parsedData); // 데이터 업데이트
      calculateTotals();
    },
    error: function (jqxhr, status, error) {
      console.log(jqxhr, status, error);
    }
  });
}, 5000);

반응형
댓글