2014-01-19 77 views
0

我使用的Neo4j REST API和做一個jQuery的AJAX調用這是我第一次與RESTNeo4j的訪問控制頭

我試圖做這樣的呼籲:使用

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

這一點,我得到以下錯誤:

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. 

在此之後我用Google搜索,並得到了答案HERE,但我不理解的錯誤,所以我谷歌d還,但它不是任何幫助,所以如果有人能告訴我這是什麼錯誤清晰的語言意味着,如果我不會刪除contenttype條款它在未來

由於產生問題,金潤

回答

2

使用:

$.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請求。 如果你讓一個OPTIONS請求您的Neo4j休息API URL(使用Fiddler或其他HTTP請求製造商),你會發現,它亙古不變的包含somwthing像:

Access-Control-Allow-Headers: content-type 
在響應頭,這是

爲什麼當過您發表的帖子電話,其選項亙古不變的有「訪問控制允許報頭」,將被拒絕

同樣是解釋here

+0

爲什麼在這裏刪除的contentType? –

+1

請參閱編輯... – MYK