FRONTEND/기타
로또 번호 가져오기
죠으닝
2023. 10. 6. 11:39
로또번호요청.html 생성
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>로또번호요청</title>
<!-- 제이쿼리CDN -->
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"
></script>
</head>
<body>
<div class="container">
<div id="result"></div>
</div>
<script>
$.ajax({
url: "https://www.dhlottery.co.kr/common.do?method=getLottoNumber&drwNo=1087", //서버의 URL주소
method: "GET", // HTTP 요청 방식(GET,POST)
dataType: "json", // 서버에서 보내줄 데이터의 타입
}).done(function (data) {
// .done 위의 자료를 받는게 성공했을 경우
console.log(data); //성공 시 데이터 콘솔로 출력
});
</script>
</body>
</html>
https://kadosholy.tistory.com/23
로또 api를 이용하여 로또번호 가져오기
로또 api를 이용하여 로또번호 가져오기 로또 관련 앱이나 프로그램을 만드려고 하면 로또 당첨번호를 알 필요가 있는데 현재 복권 판매 홈페이지나 관련 웹 사이트를 찾아봐도 공식적으로 로또
kadosholy.tistory.com
CORS 에러 보안에러임
🌐 악명 높은 CORS 개념 & 해결법 - 정리 끝판왕 👏
악명 높은 CORS 에러 메세지 웹 개발을 하다보면 반드시 마주치는 멍멍 같은 에러가 바로 CORS 이다. 웹 개발의 신입 신고식이라고 할 정도로, CORS는 누구나 한 번 정도는 겪게 된다고 해도 과언이
inpa.tistory.com
Allow CORS: Access-Control-Allow-Origin
Easily add (Access-Control-Allow-Origin: *) rule to the response header.
chrome.google.com
활성화 하면
잘 사용된다.
하지만 확장프로그램이 근본적인 해결책은 아니라고 함.
<script>
$.ajax({
method: "GET", // HTTP 요청 방식(GET,POST)
dataType: "json", // 서버에서 보내줄 데이터의 타입
}).done(function (data) {
// .done 위의 자료를 받는게 성공했을 경우
console.log(data); //성공 시 데이터 콘솔로 출력
// $("#result").parent(`<h2>${data.drwNo}</h2>`);
$("#result").html(
`
<h1>${data.drwNo}회 로또 당첨번호는?</h1>
<h2>로또날짜 : ${data.drwNoDate}<h2>
<h3>1번 : ${data.drwtNo1} <br>
2번 : ${data.drwtNo2} <br>
3번 : ${data.drwtNo3} <br>
4번 : ${data.drwtNo4} <br>
5번 : ${data.drwtNo5} <br>
6번 : ${data.drwtNo6} <br>
보너스번호 : ${data.bnusNo} <br>
</h3>`
);
});
</script>
객체는 하나라 반복문 사용할 필요없이 바로 값을 가져옴
확장프로그램 사용안하면 꺼야함