template in Flask on JS click event

This question already has an answer here:

  • replace div content using ajax and jquery 4 answers
  • How to manage a redirect request after a jQuery Ajax call 30 answers

  • $.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 <head> 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";
    }
    
    链接地址: http://www.djcxy.com/p/12464.html

    上一篇: Flask如何在ajax调用后重定向到新页面

    下一篇: JS烧瓶上的模板点击事件