Forwarding values in a JavaScript function in a post manner

Asked 2 years ago, Updated 2 years ago, 49 views

function fn_edit_username(method, path) {

        method = method || "post";
        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", path);

        swal({   title: "An input!",
                  text: "Write something interesting:",
                  type: "input",
                  showCancelButton: true,
                  closeOnConfirm: false,
                  animation: "slide-from-top",
                  inputPlaceholder: "Write something"
          }, }, function(inputValue) {
                if (inputValue === false)
                  return false;

                if (inputValue === "") {
                  swal.showInputError("You need to write something!");
                  return false;
                }

                swal("Nice!", "You wrote: " + inputValue, "success");
                document.body.appendChild(form);
                form.submit();

            });


      }

node.js web app. I want to receive input data from the pop-up window and save this value in mysql.

But I was out of my mind.

How do I transfer the value?

I thought it would be okay to do it with post? so I looked it up and tried to try the code together.

app.post('/edit_username', function(req, res) {
  pool.getConnection(function(err, conn) {
      console.log(req.body.editname);

    });
});

But I don't know how to get the price from app.js. I tried to get it with the above, but it's not worth it.

Please let me know if there is a good way or reference document.

node.js javascript

2022-09-22 21:32

1 Answers

It seems that you are using express, but bodyParser has not been added.

The usage of this part depends on the express version, so it is necessary to check the document that fits the right version.

Express Document

Please check if the similar part below is added.

// init modules
app.use(express.bodyParser());


2022-09-22 21:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.