我想從jquery調用Neo4j API。在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.
,當我從高級REST客戶端嘗試,它返回正確的響應。請參考下面的代碼
$(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 + ')')
});
});
});
http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript – 2014-10-31 07:32:43
@RubyRacer我的代碼也是一樣的而我做了crossDomain true – 2014-10-31 07:41:53