Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
ERROR OBTENER 400 (SOLICITUD INCORRECTA) al publicar con ajax (JavaScript) y matraz (Python)

Estoy tratando de hacer una solicitud POST con ajax en js:

 function func() { var gameName = document.getElementById("gname").value; // var uuid = create_UUID() const dataSend ={ "user input": { "game_name": gameName } } console.log("data from user"); console.log(dataSend); $.ajax({ url: 'http://127.0.0.1:5000/responer', contentType: 'application/json', cache: false, method: 'POST', dataType: 'json', data: JSON.stringify(dataSend), success: function(data) { alert.log(data); }, error: function (xhr, ajaxOptions, thrownError) { console.log("ERROR Status:", xhr.status ,"-", thrownError) } }); };

pero me sale el error:

127.0.0.1 - - [04/jul/2022 15:04:17] "OPCIONES /responer?{%22user%20input%22:{%22game_name%22:%22gta%22}}&_=1656936257232 HTTP/1.1" 200 -

400 -

Cuando estoy trabajando con Postman, todo funciona bien y obtengo la respuesta:

127.0.0.1 - - [04/Jul/2022 15:01:12] "POST /responer HTTP/1.1" 200 -

Mi lado de python usando matraz:

 from flask import Flask, request, jsonify, render_template from flask_cors import CORS import main import json app = Flask(__name__) CORS(app) # cors = CORS(app) #Create the receiver API POST endpoint: @app.route("/responer", methods=["POST","GET"]) def postME(): request_data = request.get_json() print("data recived: " + str(request_data)) res_data = main.response(request_data) #method that returns the response json response = app.response_class( response=json.dumps(res_data), status=200, mimetype='application/json' ) return response
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Puedes cerrar la pregunta. Mi problema fue que agregué

 type:'post'

en vez de

 method:'POST'

en mi solicitud de ajax.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda