Skip to content

Commit

Permalink
Added index.html and calling API from JS
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrajaci committed Jul 22, 2020
1 parent a60b4af commit 3ef05c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, jsonify, request
from flask import Flask, jsonify, request, render_template

app = Flask(__name__)

Expand All @@ -15,6 +15,11 @@
]


@app.route('/')
def home():
return render_template('index.html')


# POST /store data: {name:}
@app.route('/store', methods=['POST'])
def create_store():
Expand Down
25 changes: 25 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script type="text/javascript">
function httpGetAsync(theUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
httpGetAsync('http://127.0.0.1:5000/store', function(response){
alert(response);
})
</script>
</head>
<body>

<div id="myElement">
Hello, world!
</div>



</body></html>

0 comments on commit 3ef05c6

Please sign in to comment.