JavaScript Fetch API請求和響應
//載入進場工人不安全行為資料 var loadAllWorkerUsafeData = setInterval(function(){ const url = `http://35.98.90.55/api/info?project=23`; fetch(url).then(response => response.json()).then(data => { var handle_count=0; var uhandle_count=0; $("#ulist").empty(); for(var k1=0;k1<data.data.length;k1++) { var isU=data.data[k1]['u']; var f1=data.data[k1]['f']; if(!isU){ var usafe_text=""+data.data[k1]['g1']+" "+data.data[k1]['h1']+" "+formatTimestamp(data.data[k1]['t1']); var li_text=""; $("#ulist").append(li_text); uhandle_count++; } else{ handle_count++; } } // loadUSafeDataHandle(handle_count,uhandle_count); var span1 = document.getElementById("total_num1"); span1.innerText = ""+(handle_count+uhandle_count); }).catch(error => console.error('Error fetching weather:', error)); console.log("===------====="); },50000);
#####################