weixin_33738555 2014-01-19 16:58 采纳率: 0%
浏览 82

neo4j访问控制标头

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

Thanks Alot

  • 写回答

1条回答 默认 最新

  • weixin_33725722 2014-01-19 18:21
    关注

    use:

    $.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);
                }
            });
    

    EDIT:

    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
    

    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

    Same is explained here

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器