Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
Get rendered template in return from AJAX POST request and refresh the page (not working)

I am trying to send a post request using ajax and refresh my page with the rendered template returned from backend, It refreshes the page but it is not working like it is supposed to, The javascript is broken.

Is there any other way to do this?

Please find the simplified version of the code below:

JAVASCRIPT

$.ajax({
    url: "/post_data",
    type: 'POST',
    contentType: false,
    data: myForm,
    success: function(data){
        console.log("data posted")
        //rendered tempalte returned used to overwrite document
        document.write(data)
    }
    })

PYTHON

app.route("/")
def index(dataName=""):

    if dataName:
        #perform some changes in myTest.html
        print("dataname: ", dataName)
        
    return render_template("myTest.html")    


@app.route('/post_data',methods=["GET","POST"])
def post_data():
    myData = request.form["myDataName"]
    
    #return rendered template returned from index function
    return index(myData)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda