2016-02-25 48 views
0

首先,我看到了很多資源,並嘗試過但沒有運氣。簡單的角度帖子請求返回錯誤

我想通過發佈兩個變量從節點服務器獲取一些數據。

注意:我寧願不使用JQuery如果可能的話

我認爲這個問題是在這裏:

var data = { 
     "username": "trumpt", 
     "offset": "0" 
     }; 

這裏是一個小提琴 http://jsfiddle.net/pa21anen/

編輯: 我收到輸出爲{"errors":"Invalid Input"},但它應該是具有相同的URL和數據和請求類型。我已經成功地實現了它在Android,iOS設備的窗口10應用

{ 
    "notifications": [ 
    { 
     "id": 1, 
     "sender": "trumpt", 
     "title": "test 1", 
     "body": "Hello,\nFor all of those who use neo4j as a database along side with node.js, I have created a service that mediates any listing, finding or filtering request between an api and a neo4j database. The communication is done over rest api. \nThis service alows you to find/list any node from within your neo4j database using related nodes properties (from any relationship distance) \nIt was build as light as possible and it's only purpose is to generate appropriate cypher queries based on given filters and not intens processing\nIt is very easy to deploy and use.\nIssues, Pull requests and Enhancement requests are very welcomed and encouraged ! grin emoticonHello,\nFor all of those who use neo4j as a database along side with node.js, I have created a service that mediates any listing, finding or filtering request between an api and a neo4j database. The communication is done over rest api. \nThis service alows you to find/list any node from within your neo4j database using related nodes properties (from any relationship distance) \nIt was build as light as possible and it's only purpose is to generate appropriate cypher queries based on given filters and not intens processing\nIt is very easy to deploy and use.\nIssues, Pull requests and Enhancement requests are very welcomed and encouraged ! grin emoticonHello,\nFor all of those who use neo4j as a database along side with node.js, I have created a service that mediates any listing, finding or filtering request between an api and a neo4j database. The communication is done over rest api. \nThis service alows you to find/list any node from within your neo4j database using related nodes properties (from any relationship distance) \nIt was build as light as possible and it's only purpose is to generate appropriate cypher queries based on given filters and not intens processing\nIt is very easy to deploy and use.\nIssues, Pull requests and Enhancement requests are very welcomed and encouraged ! grin emoticon\nHello,\nFor all of those who use neo4j as a database along side with node.js, I have created a service that mediates any listing, finding or filtering request between an api and a neo4j database. The communication is done over rest api. \nThis service alows you to find/list any node from within your neo4j database using related nodes properties (from any relationship distance) \nIt was build as light as possible and it's only purpose is to generate appropriate cypher queries based on given filters and not intens processing\nIt is very easy to deploy and use.\nIssues, Pull requests and Enhancement requests are very welcomed and encouraged ! grin emoticon", 
     "priority": 3, 
     "time": 1455503708, 
     "type": 1, 
     "attachments": "image458286.jpg,pdf-sample.pdf,sample.doc,SampleGrades.xls" 
    }, 
    { 
     "id": 2, 
     "sender": "trumpt", 
     "title": "test 2", 
     "body": "another test notif", 
     "priority": 1, 
     "time": 1455474927, 
     "type": 1, 
     "attachments": "oimage458286.jpg" 
    }, 
    { 
     "id": 3, 
     "sender": "trumpt alter", 
     "title": "test by new user", 
     "body": "just a frickin' test", 
     "priority": 2, 
     "time": 1455478746, 
     "type": 1, 
     "attachments": null 
    } 
    ] 
} 
+0

問題的本質究竟是什麼? 「沒有運氣」是不夠的,我們理解這個問題 –

+0

檢查小提琴請 –

+0

我檢查了它,但我不知道從小提琴是否是服務器問題或不(你可以添加到服務器端代碼,它可能會幫助) –

回答

1

這是這樣,你怎麼可以序列化數據,而不JQuery的在AngularJS張貼到服務器。

.controller('myCtrl', function($scope, $http, $httpParamSerializerJQLike) { 
    $scope.SendData = function() { 

     var data = { 
     "username": "trumpt", 
     "offset": "0" 
     }; 

     $http({ 
      method: 'POST', 
      url: 'https://trumpt-nigharsh.c9users.io/notifications/getAll', 
      data: $httpParamSerializerJQLike(data), 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 

     }).success(function(data, status, headers, config) { 
      $scope.PostDataResponse = data; 
     }) 
     .error(function(data, status, header, config) { 
      $scope.PostDataResponse = data 
     }); 
    }; 

工作樣本這裏:https://plnkr.co/edit/Wp3dj6FBIq09V3tbDPV0?p=preview

NB!這個序列化僅在一些後者的AngularJS版本中引入。測試1.4.8 編輯: 短版POST:https://plnkr.co/edit/EGXIBJV24H0u7QO8JYEX?p=preview

+0

爲我工作...偉大 –