0

Below is the code to make a post request to node js api using ajax

$.ajax({
    url: "http://localhost:5555/submit",
    type: "POST",
    data :{formData: JSON.stringify(formdata)},
    dataType: "json",
    beforeSend: function(x) {
        if (x && x.overrideMimeType) {
            x.overrideMimeType("application/j-son;charset=UTF-8");
        }
    },
    success: function(data) {
        console.log("Data: " + data + "\nStatus: " + status);
        alert("Data: " + data + "\nStatus: " + status);
        location.reload();
    }         
});

NOde-js code to consume the above post request and perform functionalities:

app.post('/submit', function(req, res){
    console.log('request received by the submit endpoint');
    console.log(req.data);
    console.log(req.formData);
    var ipaddr;
    console.log(req);
});
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
niku
  • 51
  • 2
  • 7

0 Answers0