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

226
Visualizações
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 Respostas
Responde à pergunta

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