2014-12-02 126 views
0

我想執行這個查詢來打印我本地neo4j數據集的所有記錄(MATCH(n)RETURN(n))。現在我只是在控制檯({「statements」:[{「statement」:「MATCH(n)RETURN(n)」}]}(15:48:43:830)處獲得'body'的字符串值。 public_html/index.html:33)如何將neo4j-queries打印到控制檯? (Javascript)

我該如何做到這一點?

這是我的代碼:

var body = JSON.stringify({ 
      statements: [{ 
       statement: 'MATCH (n) RETURN (n)' 
      }] 
     }); 
$.ajax({ 
    url: "http://localhost:7474/db/data/transaction/commit", 
    type: "POST", 
    data: body, 
    dataType: "json", 
    contentType: "application/json" 


    }) 

      .done(function(result){ 
      console.log(body); 

     }) 
     .fail(function(error){ 
      console.log(error.statusText); 
     }); 

         </script>  

回答

1

您提交查詢後body的價值不會改變,你得到一個字符串,因爲它是您開始使用相同的字符串。服務器的響應是result。它將是一個包含兩個元素的數組,errorsresults。例如,要深入查看單個結果,您可以查看result.results[0].data[0].row[0]

var body = JSON.stringify({ 
    statements: [{ 
     statement: 'MATCH (n) RETURN n' 
    }] 
}); 
$.ajax({ 
    url: "http://localhost:7474/db/data/transaction/commit", 
    type: "POST", 
    data: body, 
    dataType: "json", 
    contentType: "application/json" 
    }) 
    .done(function(result){ 
     console.log(result.results[0].data[0].row[0]); 
    }) 
    .fail(function(error){ 
     console.log(error.statusText); 
    }); 

請注意,就JS而言,Cypher錯誤不會算作失敗。您需要將您的result值發送給另一個函數進行評估。