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

213
Visualizações
Flask POST variable to be used in GET method

In my html template user enters multiple inputs to Select2 box, and I would like to populate rest of form inputs based on SQLite DB search for Select2 multi inputs in same GET response without reloading page. But I understand that I can not update server's GET response with new data. Is there a way to do it? On javascript I can not update HTML elements inner text because python has access to DB. As there are multiple inputs on select2 box instead of 1, I need to implement SQL query.

@app.route('/Enter', methods = ['POST','GET'])
def enter_case():
    if request.method == 'POST':
        MM_entered = request.get_json()  
        con = sqlite3.connect('DB.sql')
        curs = con.cursor()
        trace_masks = curs.executemany("""select Trace_Mask,MM,Description from TRACES where MM=?;""",MM_entered).fetchall()
        con.close()
        
#GET portion
    con = sqlite3.connect('DB.sql')
    curs = con.cursor()
    trace_masks = curs.execute("""select Trace_Mask,Framework_Trace_Mask,Description,MM from TRACES""").fetchall()
    con.close()

    trace,fr_trace,tr_Desc,MM = zip(*trace_masks)

    return render_template("Enter.html", data = trace,dataf = fr_trace, mm_list=MM) 

What I would like to add on GET:

    return render_template("Enter.html", data = trace_masks ). --> I want to add POST part, SQL response data here

JS

var mm_entered = new Array()

$('.mm_button').on('mouseover',e => {

    mm_entered = $('.js-example-basic-multiple').val()

    document.querySelector(".h8").innerHTML =
    document.querySelector(".Trace").style.display = "inline"

    const request = new XMLHttpRequest()
    request.open('POST',"Enter",true)
    request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8')
    request.send(JSON.stringify(mm_entered))

})
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