working post on js

This commit is contained in:
Yaman Qalieh 2018-01-31 17:12:54 -05:00
parent b6c87fa506
commit 6b9df945d3
2 changed files with 28 additions and 3 deletions

View File

@ -151,7 +151,6 @@ def backend():
for phoneme, value in recieved['phonemes'].items():
with db.session.no_autoflush:
search = Phoneme.query.filter_by(name=phoneme).first()
print(search)
if not search:
search = Phoneme(name=phoneme)
db.session.add(search)
@ -173,17 +172,20 @@ def backend():
# Manipulate Updates
@app.route("/updates", methods=["GET", "POST", "PATCH"])
def updates():
if request.method == "POST":
recieved = request.get_json()
update = Update(author=recieved['author'],
title=recieved['title'],
content=recieved['content'])
db.session.add(update)
elif request.method == "PATCH":
update = Update.query.filter_by(id=recieved['id']).first()
update.name = recieved['author']
update.title = recieved['title']
update.content = recieved['content']
db.session.commit()
return jsonify([{"author": update.name,
"id": update.id,
@ -192,5 +194,6 @@ def updates():
"date": update.date}
for update in Update.query.all()])
# if __name__ == "__main__":
# app.run(host="0.0.0.0")
if __name__ == "__main__":
app.run(host="0.0.0.0")

View File

@ -22,6 +22,28 @@ var dropOp = {
var dropOpStore = {};
// Left This so that the post function can be reused
// function temporary(data) {
// for(var i = 0; i < data.length; i++) {
// $.ajax({
// url: serverURL + '/server',
// type: 'POST',
// data: JSON.stringify(data[i]),
// dataType: "json",
// contentType: 'application/json;charset=UTF-8'
// })
// .then(
// function success(data) {
// console.log(data);
// },
// function error(e) {
// console.log(e);
// }
// );
// }
// }
function createNav() {
for (var i = 0; i < navi.length; i++) { // Create navigation tabs.
var side = document.getElementById("sidebar");