Send post request without refreshing in nodejs/ express
up vote
0
down vote
favorite
<% Me.out.forEach(function(req){ %>
<div class="card">
<div class="content">
<div class="header"> <%= req %> </div>
</div>
<form class="ui form" action="/cancel/<%= req %>" method="post">
<input type="submit" value="Cancel" class="ui bottom attached button">
</form>
</div>
<% }); %>
The code above is an EJS code snippet where 'Me' is a MongoDB object and 'out' is an array in it. This snippet is for canceling the friend requests which is a part of my project. So, when the cancel button is clicked, it makes a POST request which eventually refreshes the current page.
The code snippet for POST request is:
app.post('/cancel/:krypter', function(req, res){
Krypters.findOne({handle: req.params.krypter}, function(err, cancel){
// code for cancelling the request and modifying DB values goes here //
});
res.redirect('/home');
});
I am aware that the res.redirect('/home') is the reason for refreshing the current page. But how do I achieve this without refreshing the page? Kindly help me with the necessary code.
javascript node.js express post ejs
add a comment |
up vote
0
down vote
favorite
<% Me.out.forEach(function(req){ %>
<div class="card">
<div class="content">
<div class="header"> <%= req %> </div>
</div>
<form class="ui form" action="/cancel/<%= req %>" method="post">
<input type="submit" value="Cancel" class="ui bottom attached button">
</form>
</div>
<% }); %>
The code above is an EJS code snippet where 'Me' is a MongoDB object and 'out' is an array in it. This snippet is for canceling the friend requests which is a part of my project. So, when the cancel button is clicked, it makes a POST request which eventually refreshes the current page.
The code snippet for POST request is:
app.post('/cancel/:krypter', function(req, res){
Krypters.findOne({handle: req.params.krypter}, function(err, cancel){
// code for cancelling the request and modifying DB values goes here //
});
res.redirect('/home');
});
I am aware that the res.redirect('/home') is the reason for refreshing the current page. But how do I achieve this without refreshing the page? Kindly help me with the necessary code.
javascript node.js express post ejs
What you are talking about ( though you don't seem to realize ) is xhr, which is actually handled in JavaScript and requires you to send data in responses rather thanrender()
orredirect()
. Just one "small" part of the picture Submit form without page reloading
– Neil Lunn
Nov 20 at 7:09
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
<% Me.out.forEach(function(req){ %>
<div class="card">
<div class="content">
<div class="header"> <%= req %> </div>
</div>
<form class="ui form" action="/cancel/<%= req %>" method="post">
<input type="submit" value="Cancel" class="ui bottom attached button">
</form>
</div>
<% }); %>
The code above is an EJS code snippet where 'Me' is a MongoDB object and 'out' is an array in it. This snippet is for canceling the friend requests which is a part of my project. So, when the cancel button is clicked, it makes a POST request which eventually refreshes the current page.
The code snippet for POST request is:
app.post('/cancel/:krypter', function(req, res){
Krypters.findOne({handle: req.params.krypter}, function(err, cancel){
// code for cancelling the request and modifying DB values goes here //
});
res.redirect('/home');
});
I am aware that the res.redirect('/home') is the reason for refreshing the current page. But how do I achieve this without refreshing the page? Kindly help me with the necessary code.
javascript node.js express post ejs
<% Me.out.forEach(function(req){ %>
<div class="card">
<div class="content">
<div class="header"> <%= req %> </div>
</div>
<form class="ui form" action="/cancel/<%= req %>" method="post">
<input type="submit" value="Cancel" class="ui bottom attached button">
</form>
</div>
<% }); %>
The code above is an EJS code snippet where 'Me' is a MongoDB object and 'out' is an array in it. This snippet is for canceling the friend requests which is a part of my project. So, when the cancel button is clicked, it makes a POST request which eventually refreshes the current page.
The code snippet for POST request is:
app.post('/cancel/:krypter', function(req, res){
Krypters.findOne({handle: req.params.krypter}, function(err, cancel){
// code for cancelling the request and modifying DB values goes here //
});
res.redirect('/home');
});
I am aware that the res.redirect('/home') is the reason for refreshing the current page. But how do I achieve this without refreshing the page? Kindly help me with the necessary code.
javascript node.js express post ejs
javascript node.js express post ejs
edited Nov 20 at 12:12
asked Nov 20 at 6:59
Surya Swanoff
145
145
What you are talking about ( though you don't seem to realize ) is xhr, which is actually handled in JavaScript and requires you to send data in responses rather thanrender()
orredirect()
. Just one "small" part of the picture Submit form without page reloading
– Neil Lunn
Nov 20 at 7:09
add a comment |
What you are talking about ( though you don't seem to realize ) is xhr, which is actually handled in JavaScript and requires you to send data in responses rather thanrender()
orredirect()
. Just one "small" part of the picture Submit form without page reloading
– Neil Lunn
Nov 20 at 7:09
What you are talking about ( though you don't seem to realize ) is xhr, which is actually handled in JavaScript and requires you to send data in responses rather than
render()
or redirect()
. Just one "small" part of the picture Submit form without page reloading– Neil Lunn
Nov 20 at 7:09
What you are talking about ( though you don't seem to realize ) is xhr, which is actually handled in JavaScript and requires you to send data in responses rather than
render()
or redirect()
. Just one "small" part of the picture Submit form without page reloading– Neil Lunn
Nov 20 at 7:09
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387769%2fsend-post-request-without-refreshing-in-nodejs-express%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What you are talking about ( though you don't seem to realize ) is xhr, which is actually handled in JavaScript and requires you to send data in responses rather than
render()
orredirect()
. Just one "small" part of the picture Submit form without page reloading– Neil Lunn
Nov 20 at 7:09