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

167
Visualizações
Python Flask and JQuery.post Are Not Working Together

I am creating a very simple dashboard for automating a task. Security is not a concern here because I am only local hosting.

JQuery Code

$.post("/approve", data={"title":title,"content":content}, success=function(){
      window.location.reload(true)
});

Flask Code

@app.post('/approve')
def approve_topic():
  args = request.args
  print(args)
  json.dump(args, open("topics/"+uuid4().hex+".json", "w"))
  return {"status":"clear"}

Result (the JSON file)

{}

Expected Result

{"title":"whatever the title is", "content":"whatever the content is"}

Any idea why this is happening? The first time I ran this it worked just fine, but now no matter what I reset or what I do it won't work.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just tested the code, it is working fine with request.form. Flask Code:

from flask import Flask, request
app = Flask(__name__)

# you can ignore this function as you're doing request on same origin
@app.after_request
def allow_cors_origin(response):
    """Resolve CORS error"""
    response.headers.add("Access-Control-Allow-Origin", "*")
    response.headers.add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,PATCH,OPTIONS")
    return response


@app.route("/echo", methods=["POST"])
def echo():
    data = request.form
    print(data)  # Output: ImmutableMultiDict([('a', '1')])
    return data 


app.run(debug=True)

jQuery Code:

$.post("http://localhost:5000/echo", {a: 1}, r=>console.log("response: ", r))
// Output: response:  {a: '1'}
about 4 years ago · Juan Pablo Isaza Relatório
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