오류 회고) Uncaught TypeError: Cannot read properties of undefined (reading 'length')

jina Seo·2022년 7월 3일
0

왜 안될까

목록 보기
2/3

길이를 재고자 하는 변수의 값이 없거나 잘못된 상태. 변수를 체크하면 된다.

아래는 내가 한 실수

[서버]
@app.route("/mars", methods=["GET"])
def web_mars_get():
order_list = list(db.mars.find({}, {'_id': False}))
return jsonify({'samples': order_list}) ---> 2)

[프론트]
(document).ready(function () { show_order(); }); function show_order() {.ajax({
type: 'GET',
url: '/mars',
data: {},
success: function (response) {
let rows = response['orders'] ---> 1)
for (let i = 0; i < rows.length; i++)
{
let name = rows[i]['name']
let address = rows[i]['address']
let size = rows[i]['size']

     console.log(name, address, size 
     

문제 해결하는 법
1) 길이를 잴 변수 'orders'를
2) 의 samles 대신 넣어줬어야 함.
내 경우에는 샘플 복사하다가 실수한 경우....

profile
운동하는 개발자가 꿈입니다?

0개의 댓글

Powered by GraphCDN, the GraphQL CDN