Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Python Flask y JQuery.post no funcionan juntos

Estoy creando un tablero muy simple para automatizar una tarea. La seguridad no es una preocupación aquí porque solo soy un anfitrión local.

Código JQuery

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

Código de matraz

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

Resultado (el archivo JSON)

 {}

Resultado Esperado

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

¿Alguna idea de por qué sucede esto? La primera vez que ejecuté esto funcionó bien, pero ahora no importa lo que reinicie o lo que haga, no funcionará.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Acabo de probar el código, funciona bien con request.form . Código del matraz:

 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)

Código jQuery:

 $.post("http://localhost:5000/echo", {a: 1}, r=>console.log("response: ", r)) // Output: response: {a: '1'}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!