【发布时间】:2014-10-31 06:23:39
【问题描述】:
我正在尝试从 jquery 调用 Neo4j API。
当我调用 GET 请求时,它可以完美运行
GET 请求端点
http://localhost:7474/db/data/node/10
但是当我使用 json 正文调用 POST 请求时,它会返回以下错误。
POST 请求端点
http://localhost:7474/db/data/cypher
错误信息
"NetworkError: 500 Server Error - http://localhost:7474/db/data/cypher"
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:7474/db/data/cypher. This can be fixed by moving the resource to the same domain or enabling CORS.
当我从 Advance REST Client 尝试时,它会返回正确的响应。请参考以下代码
$(document).ready(function(){
$("#btnQuery").click(function(){
var Request = "{'query' : 'MATCH (Movie { name:{searchName} })-[SHOWS]-(Cinema) RETURN Cinema','params' : {'searchName' : 'Rio 2'}}";
//url = mainURL +"cypher";
url = "http://localhost:7474/db/data/cypher";
$.ajax({
url: url,
headers : {
'Authorization' : 'Bearer 5f0e0d8c2a5477d4a8e79fa2d34f84a'
},
crossDomain: true,
type: 'POST',
dataType: 'application/json',
complete: function(xhr) {
if (xhr.readyState == 4) {
if (xhr.status == 201) {
alert("Data is loaded");
clearUsers();
isUserAdd = false;
}
} else {
alert("Data is not loaded");
}
},
beforeSend: function (xhr) {
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
data: ('(' + Request + ')')
});
});
});
【问题讨论】:
-
@RubyRacer 我的代码也是相同的,而我已将 crossDomain 设为 true
标签: javascript jquery neo4j cors