在我的項目中,我使用的是 solr。在我的 jsp 頁面中,我想顯示 solr 核心的響應,但某些字段未定義或為空。我編寫了一個 ajax 調用,將響應數據放入 html 文本框中。我想檢查該字段是否未定義或為空。<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 調用中編寫了 if 語句,但它仍然給我這個錯誤。Unable to get property 'strLocation' of undefined or null reference
如果 json solr 響應未定義或在 ajax 調用中為 null
慕田峪4524236
2023-10-04 17:01:20