제품 POST 연결하기

dainchoi·2020년 11월 26일
0

프로젝트

목록 보기
6/10

app.py

@app.route('/')
def home():
   return render_template('cosmetic.html')
   
@app.route('/product', methods=['POST'])
def saving():
    return jsonify({'result': 'success', 'msg':'POST 연결'})

cosmetic.html 과 연결 할 예정

(해당 페이지는 상품 리스트를 보여주며, modal 기능의 버튼을 이용하여
상품 추천하기를 POST 할 예정입니다.)

잘 연결 됐는지 확인하기 위해서 성공 시 'POST 연결' alert 출력

cosmetic.html

function postProduct() {
   $.ajax({
          type: "POST",
          url: "/product",
          data: {},
          success: function (response) { // 성공하면
                if (response["result"] == "success") {
                  alert(response["msg"]);
                    }
                }
            })
        }

=> 연결 실패...
console 창을 보니
Uncaught ReferenceError: $ is not defined
오류가 뜸

제이쿼리 js 로딩 실패로 생각됨...

<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
        integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
        crossorigin="anonymous"></script>
        

head 부분 상단에 위 코드 작성 후
정상적으로 연결 완료 확인!!!

0개의 댓글