1

As I get full html code from python using render_template,

I want to reload full html code on current page.

I know I could use form method, and I know to use $('#A').html(response)

  1. form method : I do not use submit button,, so this is not what i am looking for.

  2. $('#A').html(response) : This adds the code from where id A. When using this code my full html code duplicate inside current page, not overwrapping

So, I need how to reload my current page with responed full html code

I also tried

$.post('/cccc',{user_id: id}, function(response){
        window.location.replace(html(response));
    }
);

But this also occur html not defined errors.

Can someone give me some help?

임지웅
  • 121
  • 1
  • 1
  • 8
  • what does the response received looks like. console log response in function(response) and show me. It is the string containing html code, ie. ` .... ` – Vaibhav Vishal Dec 06 '18 at 05:10
  • @VaibhavVishal its whole new html code starting from `....` – 임지웅 Dec 06 '18 at 05:14
  • I'll simply insist that my [answer](https://stackoverflow.com/a/53643203/5734311) is *exactly* what you're looking for. You apparently haven't even tried my code, or you would see that it does exactly what you want. There's is no Submit button the user has to click in my solution. Everything is done invisibly to the user. It's not my fault if you don't even *try* it. –  Dec 06 '18 at 10:48
  • Possible duplicate of [Data from javascript to python(using post)](https://stackoverflow.com/questions/53642615/data-from-javascript-to-pythonusing-post) –  Dec 06 '18 at 10:51
  • This is the original question: https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit which this one and the previous two are a duplicate of –  Dec 06 '18 at 11:00

1 Answers1

0

You need to use document.write()

$.post('/cccc',{user_id: id}, function(response){
    document.open();
    document.write(response);
    document.close();
});

Demo

<html>
    <script>
     function replace(){
            const newhtml = '<html><body style="background-color: white"><p>New Content</p></body></html>';
            document.open()
            document.write(newhtml);
            document.close();
        }
    </script>
    <body>
        <p>Old Content</p>
        <a href='javascript:replace()'>Replace</a>
    </body>
</html>

JsFiddle Demo

Vaibhav Vishal
  • 6,576
  • 7
  • 27
  • 48
  • oh thanks, hmm wierd i tried `document.write()` before but that time it did not work, now it is working thanks! – 임지웅 Dec 06 '18 at 05:19