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

229
Vistas
Javascript links with Python not working (using Ajax and Flask)

I've been trying to make a website that gets information from another website (top 10 best tetris players) and then log it into my console. I'm experimenting with pandas for Python and Javascript with ajax.

The original Python code worked in nodejs, but I need it to work on a website, so I tried to adapt by using ajax.

Now I'm getting this error code1 and sometimes this error code2. I'm not sure when which one happens. Always code 404 though.

Does anyone know how to fix this? Thanks in advance!

HTML/Javascript code:

<html>

<head>

    <title>website test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
</head>

<body>
    <button>click me for nothing to happen</button>
    <script>
        function ajaxCall() {
            $.ajax({
                url: "/makeTop10",
                success: function (data) {
                    console.log(data);
                    console.log("call happened.") //extra test
                }
            });
        }
        ajaxCall();

    </script>
</body>

</html>

Python code:

from flask import Flask, render_template
import pandas as pd


app = Flask(__name__)


@app.route("/makeTop10")
def makeTop10():
    list = pd.read_html("https://listfist.com/list-of-tetris-high-scores-nes-pal")

    data = list[0]
    output = ""
    for i in range(10):
        output += "{: <10}{: <20}{: <25}\n".format(
            data.at[i, "Rank"],
            data.at[i, "Player Name"],
            data.at[i, "Score(2 April, 2022)[source]"],
        )

    return output


if __name__ == "__main__":
    app.run()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I just changed your code to this and it's working

HTML/Javascript code:

<html>

<head>

    <title>website test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
</head>

<body>
    <button>click me for nothing to happen</button>
    <script>
        function ajaxCall() {
            $.ajax({
                url: "http://127.0.0.1:5000/makeTop10",
                success: function (data) {
                    console.log(data);
                    console.log("call happened.") //extra test
                }
            });
        }
        ajaxCall();

    </script>
</body>

</html>

Python code:

from flask import Flask, render_template
import pandas as pd
from flask_cors import CORS # added

app = Flask(__name__)
CORS(app) # added

@app.route("/makeTop10")
def makeTop10():
    list = pd.read_html("https://listfist.com/list-of-tetris-high-scores-nes-pal")

    data = list[0]
    output = ""
    for i in range(10):
        output += "{: <10}{: <20}{: <25}\n".format(
            data.at[i, "Rank"],
            data.at[i, "Player Name"],
            data.at[i, "Score(2 April, 2022)[source]"],
        )

    return output

if __name__ == "__main__":
    app.run()

Result:
enter image description here

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