Skip to content

Commit

Permalink
now server return error to client
Browse files Browse the repository at this point in the history
  • Loading branch information
jakbin committed Jun 11, 2022
1 parent 4455914 commit 825f59c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions app-DBjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ def custom_response(res, status_code):
@app.route("/insertdata", methods = ['POST'])
def insertdata():
add_data = request.get_json()
db.add(User, add_data)
return "1"
res = db.add(User, add_data)
return res

@app.route("/updatedata", methods = ['POST'])
def updatedata():
update_data = request.get_json()
db.update(User, update_data, 'sno')
return "1"
res = db.update(User, update_data, 'sno')
return res

@app.route("/deletedata", methods = ['POST'])
def deletedata():
delete_data = request.get_json()
db.delete(User, delete_data)
return "1"
res = db.delete(User, delete_data)
return res

if __name__ == "__main__":
app.run(debug=True)
Expand Down
Binary file modified fajax.db
Binary file not shown.
13 changes: 6 additions & 7 deletions templates/index-DBjson.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ <h2>Edit Form</h2>
dataType : "json",
contentType : "application/json; charset=utf-8",
success : function(data){
if (data == 1) {
if (data.status == true) {
loaddata();
$('#addForm').trigger("reset");
message('Data has been Saved !', true);
}else{
alert("Can't Save Record.");
alert(data.data);
}
}
});
Expand All @@ -166,11 +166,11 @@ <h2>Edit Form</h2>
dataType : "json",
contentType : "application/json; charset=utf-8",
success : function(data){
if (data == 1){
if (data.data == true){
loaddata();
message('Data has been Deleted !', true);
}else{
alert("Can't Delete Record.");
alert(data.data);
}
}
});
Expand All @@ -193,7 +193,6 @@ <h2>Edit Form</h2>
$('#modal').hide();
});

//Update Record------------------------------------------
$(document).on("click", "#edit-submit", function(e){
e.preventDefault();

Expand All @@ -211,12 +210,12 @@ <h2>Edit Form</h2>
dataType : "json",
contentType : "application/json; charset=utf-8",
success : function(data){
if (data == 1) {
if (data.status == true) {
loaddata();
message('Data has been Saved !', true);
$('#modal').hide();
}else{
alert("Can't Save Record.");
alert(data.data);
}
}
});
Expand Down

0 comments on commit 825f59c

Please sign in to comment.