我需要通過java腳本獲取solr查詢響應。我做了以下代碼來獲得響應。但是響應文本只顯示空字符串。它不會從solr中檢索數據。請指導我我犯的錯誤。謝謝..通過javascript獲取Solr響應爲json
function getSolrResponse() {
var strURL = "http://localhost:8983/solr/Core1/select";
var xmlHttpReq = false;
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpReq.open('POST', strURL, true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpReq.onreadystatechange = function() {
if (xmlHttpReq.readyState == 4) {
alert(xmlHttpReq.responseText);
}
};
xmlHttpReq.send("q=*:*&wt=json");
}
的代碼似乎是正確的。你可以嘗試直接查詢這個curl -d「q = *:*&wt = json」http:// localhost:8983/solr/Core1/select來查看會發生什麼。您的問題可能出現在solr服務器配置中。試着用http:// localhost:8983/solr –