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

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

如果 json solr 響應(yīng)未定義或在 ajax 調(diào)用中為 null

如果 json solr 響應(yīng)未定義或在 ajax 調(diào)用中為 null

慕田峪4524236 2023-10-04 17:01:20
在我的項(xiàng)目中,我使用的是 solr。在我的 jsp 頁(yè)面中,我想顯示 solr 核心的響應(yīng),但某些字段未定義或?yàn)榭?。我編?xiě)了一個(gè) ajax 調(diào)用,將響應(yīng)數(shù)據(jù)放入 html 文本框中。我想檢查該字段是否未定義或?yàn)榭铡?lt;script>function openForm(){    document.getElementById("myForm").style.display = "block";    var salesOrder="\"" + $("#sOrder option:selected").val()+ "\"";    document.getElementById("sOrder_popup").value=$("#sOrder option:selected").val();    var URL_PREFIX="http://localhost:8983/solr/StorageCore/select?q=strSO:"    var URL_MIDDLE="&rows=99999&start=0&wt=json"    var URL=URL_PREFIX+salesOrder;    var loc=document.getElementById("location_popup").value;    $.ajax({        url : URL,        dataType : 'json',        type:'get',        json : 'json.wrf',        success : function(data) {            var docs = JSON.stringify(data.response.docs);            var jsonData=JSON.parse(docs);            if(jsonData[0].strLocation[0]===undefined)                document.getElementById("location_popup").value="";            else                document.getElementById("location_popup").value=jsonData[0].strLocation[0];            //document.getElementById("submitted_popup").value=jsonData[0].strSubmitName[0];        },        });}function closeForm(){    document.getElementById("myForm").style.display = "none";}</script>我在上面的 ajax 調(diào)用中編寫(xiě)了 if 語(yǔ)句,但它仍然給我這個(gè)錯(cuò)誤。Unable to get property 'strLocation' of undefined or null reference
查看完整描述

1 回答

?
慕神8447489

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

錯(cuò)誤抱怨的jsonData[0]undefined,但你正在檢查strLocation[0]。

if (jsonData[0] === undefined)

..或者可能更好:

if (jsonData.length === 0) {
    ...
}

因?yàn)檫@實(shí)際上表達(dá)了您正在做的事情(檢查是否返回 0 個(gè)結(jié)果),而不是用來(lái)undefined檢查數(shù)組索引是否存在。


查看完整回答
反對(duì) 回復(fù) 2023-10-04
  • 1 回答
  • 0 關(guān)注
  • 118 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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