-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the app.js, app.html, jquery and app.py as basic set up
- Loading branch information
0 parents
commit d2e4f4b
Showing
6 changed files
with
10,736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
flask_ajax_db-journal | ||
flask_ajax_db | ||
.vscode/ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from flask import Flask, jsonify, render_template, request | ||
import sqlite3 | ||
|
||
|
||
app = Flask(__name__) | ||
DATABASE_NAME = "flask_ajax_db" | ||
|
||
|
||
@app.route('/process', methods=['POST']) | ||
def add_numbers(): | ||
|
||
status = 0 | ||
|
||
first_name = request.form.get('firstName', '') | ||
last_name = request.form.get('lastName', '') | ||
|
||
if first_name or last_name: | ||
status = 1 | ||
result = f"{first_name} {last_name}" | ||
else: | ||
result = "Provide first or last name" | ||
|
||
response_object = { | ||
'status': status, | ||
'result': result | ||
} | ||
|
||
return jsonify(response_object=response_object) | ||
|
||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
|
||
return render_template('app.html') | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) | ||
app.secret_key = '#$%1RTY2^&3FGh4%^&*{"5)(iukVT^ioIo_\{\:DFDFHJHkjn})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BEGIN TRANSACTION; | ||
CREATE TABLE IF NOT EXISTS `info` ( | ||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
`firstname` TEXT, | ||
`lastname` TEXT | ||
); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
$(function () { | ||
$('#addName').on('click', function (e) { | ||
e.preventDefault() | ||
|
||
$.ajax({ | ||
url: '/process', | ||
type: 'POST', | ||
dataType: 'json', | ||
data: { | ||
firstName: $('#firstName').val(), | ||
lastName: $('#lastName').val() | ||
}, | ||
success: function (response) { | ||
|
||
if (response.response_object['status'] === 1) { | ||
$("#msg").text(''); | ||
$("#result").text(response.response_object['result']); | ||
} else { | ||
$("#result").text(''); | ||
$("#msg").text(response.response_object['result']); | ||
} | ||
|
||
$('#firstName').val('') | ||
$('#lastName').val('') | ||
|
||
|
||
}, | ||
error: function (error) { | ||
$('#msg').text(error.response_object); | ||
// console.log(error.response_object['result']) | ||
} | ||
|
||
}) | ||
|
||
}) | ||
|
||
}) |
Oops, something went wrong.