javascript - Express.js - Send an alert as a response while staying on same page -


i have 3 forms on view that, when submitted, add new entries in mysql database. send alert saying "you have added x" whenever entry added, without navigating page.

// form submitted <form method="post" action="route/action/">     <input type="text" name="name"> </form>   // route exports.action = function (req, res) {      client.query();      // kind of response send? } 

how can send alert? kind of response should send?

thank you!

what need ajax request express server , evaluate response , alert user accordingly. client part same other programming language.

for example. in jquery client side part can

$.ajax({  url: 'route/action/',  type: "post",  data: 'your form data',  success: function(response){   alert('evaluate response , show alert');  } });  

in epxress app can have this

app.post('route/action', function(req, res){   //process request here , db queries   //then send response. may json response   res.json({success: true}); }); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -