我正在尝试设置一个用户可以在节点编号中输入的网页,并让我的外部python代码查询neo4j,然后将该查询的结果发回网页。
我正在尝试使用AJAX的相关html代码:
<h4>Enter Node Name for Search</h4>
<input id="numb" type="text">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
<script>
function myFunction() {
var x, text;
x = document.getElementById("numb").value;
if (isNaN(x)) {
text = "Input not valid";
} else {
$.ajax({
type: "POST",
url: "python/neo.py",
dataType:"html",
data: {param: x},
success: function(data) {
document.getElementById("demo").innerHTML = $(data).text().trim();},
error: doError,
});
}
document.getElementById("demo").innerHTML = text;
}
</script>
这是python代码:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from __future__ import division
import sys
from py2neo import neo4j,node, rel, cypher
url = "http://localhost:7474/db/data/"
def node_info(a):
try:
graph_db = neo4j.GraphDatabaseService(url)
query = neo4j.CypherQuery(graph_db,
"""CYPHER 2.0
MATCH (n)-[r*..2]-(m)
WHERE id(n)={z}
RETURN labels(n), count(m) AS connected_count, collect (id(m)) as connected_nodes
""")
result = query.execute(z=a)
for r in result:
print r.values
except Exception as e:
print e
if __name__ == '__main__':
startnode=int(sys.argv[1])
node_info(startnode)
我希望r.values
打印到success:
块中的网页上的python代码,除非我误解了成功块的工作原理。