neo4j访问控制标头 [英] neo4j access control headers
问题描述
我正在使用neo4j REST api并进行jquery ajax调用这是我第一次使用REST
i am using neo4j REST api and doing an jquery ajax call This is my first time with REST
我正试图打这样的电话:
i was trying to make a call like this:
$.ajax({
url: "http://localhost:7474/db/data/cypher",
accepts: "application/json; charset=UTF-8",
contentType:"application/json",
dataType:"json",
data:{
"query" : "start n = node(*) return n",
"params" : {}
},
type:"POSt",
success:function(data,xhr,status)
{
console.log(data);
},
error:function(xhr,err,msg){
console.log(xhr);
console.log(err);
console.log(msg);
}
});
使用这个我得到以下错误:
using this i get following error:
XMLHttpRequest cannot load http://localhost:7474/db/data/cypher.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost' is therefore not allowed access.
after this i googled it and got the answer HERE but i dont understand the error so i googled that also but it wasnt of any help so if anyone can tell me what this error means in lucid language and If i remove the contenttype
clause wont it create a problem in future
非常感谢
推荐答案
使用:
$.ajax({
url: "http://localhost:7474/db/data/cypher",
accepts: "application/json; charset=UTF-8",
dataType:"json",
data:{
"query" : "start n = node(*) return n",
"params" : {}
},
type:"POST",
success:function(data,xhr,status)
{
console.log(data);
},
error:function(xhr,err,msg){
console.log(xhr);
console.log(err);
console.log(msg);
}
});
使用ajax调用将数据发布到服务器时,会从浏览器生成两个请求,第一个是OPTIONS(预检请求),第二个是POST请求. 如果您向neo4j rest API URL发出OPTIONS请求(使用fiddler或任何其他http请求生成器),您会发现它不包含以下内容:
when you post data to server using an ajax call, two requests are created generated from browser, first is OPTIONS(preflight request) and the second is the POST request. If you make an OPTIONS request to your neo4j rest API URL (use fiddler or any other http request maker), you will notice that it DOESNOT contain somwthing like:
Access-Control-Allow-Headers: content-type
在响应标题中,这就是为什么当您进行开机自检而其选项没有"Access-Control-Allow-Headers"时,它将被拒绝
in the response header, which is why when ever you make a post call, whose options doesnot have "Access-Control-Allow-Headers", it will be rejected
解释相同的内容 查看全文