0

The client side code snippet:

$http({
  method: 'GET',
  url: '/admin?operation=getAdminInfo',
  data: {data: 'test'}
}).then(function(rsp){...});

The server side code snippet:

console.log('req = ' + req);
console.log('req.header = ' + JSON.stringify(req.header));
console.log('req.query = ' + JSON.stringify(req.query));
console.log('req.body = ' + JSON.stringify(req.body));
console.log('req.cookies = ' + JSON.stringify(req.cookies));
console.log('req.params = ' + JSON.stringify(req.params));
console.log('req.xhr = ' + JSON.stringify(req.xhr));

The output in the server console:

req = [object Object]
req.header = undefined
req.query = {"operation":"getAdminInfo"}
req.body = {}
req.cookies = {"token":"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzeXN0ZW0iLCJpc3MiOiJodHRwczovL3d3dy5uZXRhb3RlYy5jb20iLCJpYXQiOjE1MTYwNjM1Njk1MDQsInVzZXJfcm9sZSI6MSwidXNlcm5hbWUiOiJzeXN0ZW0iLCJleHAiOjE1MTYwNjM1NzY3MDR9.K2Rh4WTNtkhP2gxWLnGW7846zMKaW-WKEF2hykJmvn3zNmGyIDprrnswzqqrpmAvNTP8gylnCn3b7K_gRJ-WOif7MnQYiG4mu8fNGW-hCUQeTyqzUgsP9sIXzm_A3pWFlW8eL88Dydugf9JhhDeB18QUJV-i4zT6bCfE3stY1QXJZzNsKd8HRl22n78XCb5XRxdiEnmhqF6sNb9h40jKzcd6Ny0KX6uEe1SE54OYbp_BcR4Lr69C6tcFNgwtiJusFEymnMcbkqSst_GUztiObPeYZIwrfEUMEobUsxvx0v2zUQp9EJDF-MyaGid5kJwyv_ittFFKRChBSllI3luNXA"}
req.params = {}
req.xhr = false

How can I extract/get the data {data: 'test'} at node.js? AngularJS version is 1.6.6; Node.js version is v8.1.4; app.js at node.js: enter link description here

6
  • @Sajeetharan, no, no. you take a look at my output, I cannot get the data at node.js. at angularjs side I'm following the instruction of angularjs document strictly. In the document it shows data – {string|Object} – Data to be sent as the request message data. Commented Jan 16, 2018 at 17:39
  • 1
    which is same! you need to strigify the data if you are sending it as ajson, also use http.post with angularjs Commented Jan 16, 2018 at 17:41
  • I changed the config to data: JSON.stringify({data: 'test'}) and get the same result. Also, at the angularjs document, there is an example using code data: { test: 'test' }. Commented Jan 16, 2018 at 17:44
  • bro check the duplicate marked question, you need to check the headers as well Commented Jan 16, 2018 at 17:45
  • Change the config method: 'GET' to method: 'POST' get the result in req.body. Thank you. But this is not duplicate with the thread you mentioned -- JSON.stringify does not help here. Commented Jan 16, 2018 at 17:47

1 Answer 1

1

Change the method from Get to Post, since you are sending an object to the server.

$http({
  method: 'POST',
  url: '/admin?operation=getAdminInfo',
  data: {data: 'test'}
}).then(function(rsp){...});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.