
강의를 봐도 이해가 잘 안돼서 이렇게 질문 드립니다.
제가 이해한 바로는 app.py에는 서버가 존재하고, index.html은 클라이언트입니다.
index.html에서 hey()함수로 ajax콜을 하면
$.ajax({
type: "POST",
url: "/test",
data: { title_give:'봄날은간다' },
success: function(response){
console.log(response)
}
})
app.py에서 /test부분을 찾아
@app.route('/test', methods=['POST'])
def test_post():
title_receive = request.form['title_give']
print(title_receive)
return jsonify({'result':'success', 'msg': '이 요청은 POST!'})
test_post() 함수를 실행하는데 그 함수는 title_give로 요청된 값을 title_receive에 저장하고 파이참 콘솔에 title_receive를 찍은다음 jsonify로 success를 다시 html로 보냅니다.
그러면 index.html에
success: function(response){
console.log(response)
}
이 부분으로 인해 크롬 검사 창에서 콘솔에 'result'와 'msg'가 찍히는 것입니다.
제가 이해가 안 가는 부분은, html에서 title_give로 '봄날은 간다'를 서버에 요청했잖아요? 그럼 서버에 title_give = '봄날은 간다'로 데이터가 미리 존재했어야 하는거 아닌가요? '봄날은 간다'가 미리 존재하지 않았는데 어떻게 클라이언트에 데이터를 줄 수가 있는건지 궁금합니다.
