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

230
Views
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 answers
Answer question

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