在我的項(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
如果 json solr 響應(yīng)未定義或在 ajax 調(diào)用中為 null
慕田峪4524236
2023-10-04 17:01:20