javascript - Data is not passed from AngularJS controller to NodeJS server -


I am trying to pass some values ​​from my client-side angles JS script to a server-side nodejs script. I established a POST request like this:

  $ scope.addUser = function () {console.log ($ .param ($ scope.user)); $ Http ({method: 'POST', url: '/ addUser', data: $ .premium ($ scope.user), header: {'Content-type': 'application / x-www-form-urlencoded'} }). Success (work (feedback) {console.log ("success");}) error (work (feedback) {console.log ("error");}); };   

$ scope.user variable {name: "john", email: "dow"} , and name = john & amp; Evaluates Email = When When Passed $ Passed through the ultimate ($ scope.user) . I originally thought that the request for the problem was the type of content, which was originally a JSON object. After reading about similar problems, I changed the content-type to the x-www-form-urlxode, but still could not take data from the POST request.

Here is a server-side nodejs script that is hit with a post request:

  app post ('/ addUser', function (rik, ridge) {console.log (req.params);});   

I know that the server-side script is being accessed because I can print the data such as the rake. Matthew, but Rick. The attempt to print a printer is only in {}.

Why are not my post parameters going?

request body has not been saved rake from the request body for you You need to add the middleware to parse. For the key = value pair provided as part of the req.params URL (for example, posting on "/ foo / bar? Baz = bla" The result will be req.params.baz === 'bla' ).

Some example solutions:

  • - Only the Application / Jason and application / x-www-form-urlencoded < / strong> Request bodies

  • - Purse Application / Jason , Application / X- www-form-URLX , and Multipart / It was used in the body parser in Express-Data Express 3. I'm not sure that this is the "official" express middleware for Express 4.

  • - Purse Application / x-www-form-urlencoded and multipart / form-data . It does not save files on the disk itself, but instead presents the files as readable streams, the API is different from the weak (body parser / 3 Express). There are some express middleware available for BSP:

    • - A thin cover that sets only a basu example on your request . You can set it to parse the request automatically, or you can pipe the request manually to req.busboy when you want to start.

    • - Express 3 provides a interface similar to body parser middleware (with req.body and req.files set).

    • - A new module that provides a layer at the top of Bujayu, which provides the same mechanism as refractory (for example saving files uploaded to disk) But other features like field validation also

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -