2
實施VisualSearch.js我試圖用jQuery的阿賈克斯,REST API和Neo4j的GraphDB在後端實現VisualSearch.js。我已經在這個link,通過使用紅寶石執行相同的職位。使用jQuery的Ajax,REST API和Neo4j的GraphDB
這是我的代碼。
var visualSearch;
$(document).ready(function() {
var facets=[];
$.ajax("/facets", {
type:"GET",
dataType:"json",
success:function (res) {
facets = res;
}
});
visualSearch = VS.init({
container : $('#search_box_container'),
query : '',
showFacets : true,
unquotable : [
'text',
'account',
'filter',
'access'
],
callbacks : {
search : function(query, searchCollection) {
var $query = $('#search_query');
var count = searchCollection.size();
$query.stop().animate({opacity : 1}, {duration: 300, queue: false});
$query.html('<span class="raquo">»</span> You searched for: ' +
'<b>' + (query || '<i>nothing</i>') + '</b>. ' +
'(' + count + ' node' + (count==1 ? '' : 's') + ')');
clearTimeout(window.queryHideDelay);
window.queryHideDelay = setTimeout(function() {
$query.animate({
opacity : 0
}, {
duration: 1000,
queue: false
});
}, 2000);
},
valueMatches : function(facet, searchTerm, callback) {
alert(facet)
var restServerURL = "http://localhost:7474/db/data";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: restServerURL,
dataType: "json",
contentType: "application/json",
data: { /*Query goes here.*/ },
success: function(data, xhr, textStatus) {
alert(data.self);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR);
alert(textStatus);
alert(errorThrown);
},
complete: function() {
alert("Address of new node: " + data.self);
}
});
},
facetMatches : function(callback) {
if(visualSearch.searchBox.value() != "") {
$.ajax("/connected_facets", {
type:"POST",
dataType:"json",
data: {/*Query goes here.*/},
success:function (res) {
callback(res);
}
});
} else {
callback(facets);
}
}
}
});
});
如果有人能指出問題,這將是一個很大的幫助。在此先感謝:-)
什麼是實際問題?你的代碼的行爲是什麼?如果沒有爲ajax調用編寫一些服務器端處理程序,我不能輕易運行此操作。 – LameCoder