
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>4주차 2회독</title>
<script>
function hey() {
$.ajax({
type: "GET",
url: "/test?title_give=봄날은간다",
data: {},
success: function (response) {
console.log(response)
}
})
};
</script>
</head>
<body>
<h1> 나의 첫 웹페이지!</h1>
<button onclick="hey()">이거슨 버튼</button>
</body>
</html>
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/test', methods=['GET'])
def test_get():
title_receive = request.args.get('title_give')
print(title_receive)
return jsonify({'result':'success', 'msg': '이 요청은 GET!'})
if __name__ == '__main__':
app.run('0.0.0.0',port=5000,debug=True)
이거슨 버튼을 클릭하면, hey()라는 함수 가 실행되는데, hey()라는 함수는 ajax콜을 해주는데, get방식으로 데이터를 가져오는데, 그것을 app.py 에 있는
/test라는 창구에서 get방식으로 받아서 찍었어요! 그럤더니! 찍혔네요!
여기까지는 코드의 뜻을 이해 했는데요!
아래 제가 캡쳐한 부분

여기서 부터 질문입니다.
return jsonify({'result: 'success', 'msg': '이 요청은 GET!'} 이 준 것이
어떤 로직으로 index.html에 있는 ajax콜 제일 아래 부분에 있는
success: function (response) { console.log(response) }
으로 가는 것인가요?
감사합니다!
