그누는 아니고 jquery 쪽 질문입니다...
likeelon
9년 전
조회 7,711
</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"><script type="text/javascript"></div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;">$(document).ready(function() {</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> $(".trans").each(function(){</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> var text = $(this).text();</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> var json_url = '/translate/translator.php?&to=ko&text=' + text;</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> var trans_data;</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> $.getJSON(json_url, function(result) {</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> trans_data = result.translation;</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> console.log(trans_data); // 여기까지 trans_data는 잘 찍히는데요</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> });</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> $(this).html(trans_data);</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"><div style="margin: 0px; padding: 0px;"> console.log(trans_data); // 여기에서는 데이터가 없네요</div></div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"> });</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;">});</div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;"></script></div><div style="margin: 0px; padding: 0px; color: rgb(64, 64, 64); font-family: gulim, sans-serif; font-size: 13px; line-height: 22.1px;">
trans 클래스의 텍스트를 모두 순차적으로 찾아서 해당 json url에서
번역한 결과 json으로 다시 받아서 기존 텍스트를 바꿔주는 코드인데요
전역변수 trans_data를 못 받아오네요 ㅜㅡ
해결법 좀 알려주세요
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
9년 전
| $.getJSON(json_url, function(result) { |
|
|
|
|
위와 같이 result 값을 제대로 가져오시는지 확인하시고,
result 값이 없다면,
브라우저에서 /translate/translator.php?&to=ko&text=값 을 직접넣어서
translator.php 가 제대로 작동하는지 확인하세요.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
l
likeelon
9년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
이부분까지 잘 나옵니다. 물론 alert(result); 도 나오고요
/translate/translator.php?&to=ko&text=값 해당 부분도 문제없습니다.
12줄에서 찍어보면 데이터가 없습니다.