ajax 기술을 사용할 때는, 웹페이지 안에서 바로 서버로 데이터를 전달할 수 있기 하기 위해 XMLHttpRequest()함수를 사용한다.
이때, 서버로 데이터를 전달하는 함수들이 있는데 , 대표적으로 open()과 send()를 들 수 있다.
open(method,url) | method : 요청의 유형 (GET 또는 POST) url : 서버의 위치 |
send() | send: 서버로 데이터 요청 (GET) |
function loadDoc(){
const xhttp = new XMLHttpRequest();
xhttp.onload = function(){
document.getElementById("demo").innerHTML =
this.responseText;
}
xhttp.open("GET","ajax_info.txt");
xhttp.send();
}
this.responseText : loadDoc()함수로 받은 데이터 결과값을 문자열로 반환
이 코드 5번 안보고 만들기 ~~
https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_first
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
www.w3schools.com
'Development (국비 복습 ) > JavaScript' 카테고리의 다른 글
Arrow Function 화살표함수 기본 (0) | 2023.02.11 |
---|---|
비동기 Async) callback (0) | 2023.02.11 |
[Ajax] .onload() 함수란 무엇일까? (0) | 2023.02.11 |
[Ajax] XMLHttpRequest 객체의 생성 (0) | 2023.02.11 |
[Ajax] ajax 기본 (0) | 2023.02.10 |
댓글