Accessing a java-script file using flask

javascript
flask

#1

Hi, I’m trying to access my ‘main.js’ file which I have in a static directory (‘static/main.js’) using flask.
I’m not getting any 404 errors when I run the flask application, so I think my main.js file is accessible, but when I “run” my main.js code within cloud 9, I receive the following error message:

" ReferenceError: XMLHttpRequest is not defined"

Here is my html code/link to the file:


 <link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">

 <script type="text/javascript" href="{{ url_for('static', filename='main.js') }}"> </script>
<div id="data"></div>

Here is my javascript code for main.js:

var xhr = new XMLHttpRequest();

//Open the connection:

xhr.open(“GET”, “https://swapi.co/api/planets/3/”);
xhr.send();

xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(“data”).innerHTML = this.responseText;
}
};


Here is my python/flask code:

@app.route(’/’)
def quiz():
return render_template(‘index.html’, riddle_data = random.choice(riddles))

if name == ‘main’:
app.run(host=os.environ.get(“IP”),
port=int(os.environ.get(“PORT”)),
debug=True)


Any and all help welcome, thanks…