목차
- load() 예제 - 데이터 로드 및 선택요소에 데이터 저장
- load() 정의
- load() 구문
load() 예제 - 데이터 로드 및 선택요소에 데이터 저장
text.txt 내용
Homzzang.com
test.php 내용
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#hz").load("test.txt");
});
});
</script>
</head>
<body>
<div id="hz">홈짱닷컴 주소?</div>
<button>알려줘.</button>
</body>
</html>
load() 정의
서버에서 데이터를 로드하고 반환된 데이터를 선택한 요소에 저장.
PS.
- load()라는 jQuery 이벤트 메서드도 있음.
- 어떤 것이 호출되는지는 매개변수에 따라 다름.
load() 구문
$(selector).load(url,data,function(response,status,xhr))
[매개변수]
url
필수. 로드 할 URL을 지정.
data
선택. 요청과 함께 서버에 보낼 데이터를 지정.
function (response, status, xhr)
선택. load () 메서드가 완료 될 때 실행할 콜백 함수를 지정.
- response - 요청 결과 데이터를 포함.
- status - 요청 상태 (가능값: "success", "notmodified", "error", "timeout", "parsererror")
- xhr - XMLHttpRequest 객체를 포함.