커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4주차 숙제 질문
undefined주차
북마크
김*민
댓글
8
추천
0
조회수
18
조회수
18
답변 완료
<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 기능만 구현하였습니다.


강의자료 해설지도 참고하였는데 어디서 문제가 나서 에러가 나는지 모르겠네요..

응원 남기기 버튼을 누르면 해당 에러가 나옵니다.

스파르타 즉문즉답

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

취소
 공유
취소
댓글 0
댓글 알림
나의얼굴