Friday 22 December 2017

javascript - render_template in Flask on JS click event

$.get just sends an HTTP request
to your server, but doesn't actually do anything anything with the data (in your case,
the rendered template) it gets back from the
server.



Try something like
this:



$("#load_btn").click(function()
{


$("html").load("/callback");
}


Or
if the template you render doesn't contain any
tags, only body content, you can
do



$("#load_btn").click(function()
{

$("body").load("/callback");
}



Or,
you can exchange "body" for a specific element to only replace a specific part of the
page.



If you want the user to be redirected, do
this:



$("#load_btn").click(function()
{
window.location =
"/callback";
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...