В моем проекте я использую solr. На моей странице jsp я хочу показать ответ моего ядра Solr, но некоторые поля не определены или имеют значение NULL. Я написал 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>
Я написал оператор if в вышеупомянутом ajax вызове, но он все еще дает мне эту ошибку.
Unable to get property 'strLocation' of undefined or null reference