最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to refresh the page with nodejs after click on submit button - Stack Overflow

programmeradmin1浏览0评论

I would need a little help from you.

I have a button which copy something and that "something" should occurs on the page instantly. The problem is that the button has the functionality to copy, but right now I have to refresh the page manually to see the changes.

I dont think this is something tricky but I have tried following without success:

<form method="post" action="/users/copy?scene=<%= scene.id %>">
  <button type="submit" class="btn btn-primary" onClick="window.location.href=window.location.href">Copy the scene</button>
</form>

I mean it works if I change "submit" to "button", but then the functionality to copy something is no longer working.

I googled, but I have not find any answer so far.

Any help would be really appreciated

So I just realized that the localhost was loading even before I added the function to refresh the page so there must be unfinished request on the server. I think it is in this function:

router.post('/copy', function(req,res,call) {

if( req.param('scene') !== undefined ){

db.serialize(function () {

 db.run("CREATE TABLE temp_table as SELECT * FROM scene where id=?", req.param('scene'));
 db.run("UPDATE temp_table SET id = NULL, user_id = (SELECT id FROM users WHERE email =?)",GLOBAL.email);
 db.run("INSERT INTO scene SELECT * FROM temp_table");
 db.run("DROP TABLE temp_table");
 // res.render('copy');
    if(error) {
        console.log(error);
    } 
});

db.close();

 }
 });

I would need a little help from you.

I have a button which copy something and that "something" should occurs on the page instantly. The problem is that the button has the functionality to copy, but right now I have to refresh the page manually to see the changes.

I dont think this is something tricky but I have tried following without success:

<form method="post" action="/users/copy?scene=<%= scene.id %>">
  <button type="submit" class="btn btn-primary" onClick="window.location.href=window.location.href">Copy the scene</button>
</form>

I mean it works if I change "submit" to "button", but then the functionality to copy something is no longer working.

I googled, but I have not find any answer so far.

Any help would be really appreciated

So I just realized that the localhost was loading even before I added the function to refresh the page so there must be unfinished request on the server. I think it is in this function:

router.post('/copy', function(req,res,call) {

if( req.param('scene') !== undefined ){

db.serialize(function () {

 db.run("CREATE TABLE temp_table as SELECT * FROM scene where id=?", req.param('scene'));
 db.run("UPDATE temp_table SET id = NULL, user_id = (SELECT id FROM users WHERE email =?)",GLOBAL.email);
 db.run("INSERT INTO scene SELECT * FROM temp_table");
 db.run("DROP TABLE temp_table");
 // res.render('copy');
    if(error) {
        console.log(error);
    } 
});

db.close();

 }
 });
Share Improve this question edited Oct 27, 2016 at 16:28 Matěj Zmítko asked Oct 27, 2016 at 14:14 Matěj ZmítkoMatěj Zmítko 3572 gold badges8 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6
$(document).ready(function(){ 
  $(form).on('submit', function(){ 
        location.reload();
  });
})

You can try something like this:

<button id="btn">
  Click me
</button>

$("#btn").click(function(){
  location.reload(true);
});

So once the btn is clicked. You reference it using jquery, then refresh the page using location.reload(true). jsfiddle: https://jsfiddle/j9nftot3/

发布评论

评论列表(0)

  1. 暂无评论