
<script>
$(document).ready(function () {
set_temp()
show_comment()
});
function set_temp() {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
$('#temp').text(response['temp'])
}
})
}
function save_comment() {
let nickname = $('#name').val()
let comment = $('#comment').val()
$.ajax({
type: 'POST',
url: '/homework',
data: {'nickname_give': nickname, 'comment_give': comment},
success: function (response) {
alert(response['msg'])
window.location.reload()
}
});
}
.
.
.
<div class="mypost">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="name" placeholder="url">
<label for="floatingInput">닉네임</label>
</div>
<div class="form-floating">
<textarea class="form-control" placeholder="Leave a comment here" id="comment"
style="height: 100px"></textarea>
<label for="floatingTextarea2">응원댓글</label>
</div>
<button onclick="save_comment()" type="button" class="btn btn-dark">응원 남기기</button> <!--save_comment실행 버튼-->
</div>
ㄴindex.html
from flask import Flask, render_template, request, jsonify
from pymongo import MongoClient
client = MongoClient('mongodb+srv://idvalue:passwordvalue@Cluster0.vlj5yqv.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route("/homework", methods=["POST"])
def homework_post():
nickname_receive = request.form['nickname_give']
comment_receive = request.form['comment_give']
doc = {
'nickname': nickname_receive,
'comment': comment_receive,
}
db.homework.insert_one(doc)
return jsonify({'msg': 'POST 연결 완료!'})
@app.route("/homework", methods=["GET"])
def homework_get():
return jsonify({'msg': 'GET 연결 완료!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
ㄴapp.py
function save_comment()
POST 기능만 구현하였습니다.
강의자료 해설지도 참고하였는데 어디서 문제가 나서 에러가 나는지 모르겠네요..
응원 남기기 버튼을 누르면 해당 에러가 나옵니다.

개발자 콘솔에서 에러가 나서 뭘 참고하고 구글링을 해야할지 감이 안잡히네요..
