第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

API函數(shù)被調(diào)用兩次導(dǎo)致重復(fù)

API函數(shù)被調(diào)用兩次導(dǎo)致重復(fù)

梵蒂岡之花 2022-12-09 16:27:24
我正在嘗試向遠(yuǎn)程服務(wù)器發(fā)送獲取 API 請求。響應(yīng)非常好,正如我想要的那樣。我正在嘗試將響應(yīng)存儲(chǔ)在一個(gè)表中。但這里的問題是該processRequest()函數(shù)被調(diào)用了兩次,這會(huì)產(chǎn)生重復(fù)的結(jié)果。我正在使用的警報(bào)也顯示了兩次。document.getElementById("ndviHsearch").onclick = function getndviHdata(){   var ndvihconvdataTime=[];   var ndvihStd=[];   var ndvihp25=[];   var ndvihmin=[];   var ndvihmax=[];   var ndvihmedian=[];   var ndvihmean=[];   var ndvihp75=[];   var ndviHfidValue = document.getElementById("ndviHfid").value;   var ndviHstartDateValue = document.getElementById("ndviHstartDate").value;   var ndviHendDateValue = document.getElementById("ndviHendDate").value;   table = document.getElementById("ndviHtable");   const xhr = new XMLHttpRequest();   ndviHstartDateValue = new Date(ndviHstartDateValue).getTime() / 1000;   ndviHendDateValue = new Date(ndviHendDateValue).getTime() / 1000;   xhr.open("GET","https://api.agromonitoring.com/agro/1.0/ndvi/history?polyid="+ndviHfidValue+"&start="+ndviHstartDateValue+"&end="+ndviHendDateValue+"&appid=APIKEY");   xhr.setRequestHeader("Content-Type","application/json");   xhr.send();   xhr.onreadystatechange = processRequest;   function processRequest(e) {     if (xhr.status==200){       response = JSON.parse(xhr.responseText);       alert (response.length);       for (var i=0; i<response.length; i++){         var dt = response[i].dt;         // Unixtimestamp         var unixtimestamp = dt;         // Months array         var months_arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];         // Convert timestamp to milliseconds         var date = new Date(unixtimestamp*1000);            var year = date.getFullYear();         var month = months_arr[date.getMonth()];         var day = date.getDate();         var hours = date.getHours();         var minutes = "0" + date.getMinutes();         var seconds = "0" + date.getSeconds();         }    }    
查看完整描述

1 回答

?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

您還需要檢查 readyState 值(xhr.readyState == 4 && xhr.status == 200)

函數(shù) xhr.onreadystatechange = processRequest;將在每次 xhr 狀態(tài)更改時(shí)執(zhí)行,您需要檢查是否readyState == 4還有status  == 200,然后執(zhí)行您的操作。


查看完整回答
反對 回復(fù) 2022-12-09
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)