AJAX-데이터 받아오기

임재헌·2023년 4월 3일
0

AJAX

목록 보기
2/10
 ACTORS.JSON
[
    {"name":"송강호","height":180,"weight":70}
   ,{"name":"정우성","height":185,"weight":75}
   ,{"name":"이정재","height":177,"weight":85}
]
<!DOCTYPE html>   
<html lang="ko"> 
<head>
    <meta charset="UTF-8">
<title>02_ajax  </title> 
<style>
    
</style>
<!-- jquery import -->
<script src="jquery-3.6.4.min.js"></script>  
</head>
<body>
<button> *JSON데이터 받아오기* </button>
<script>
$("button").click(function(){
//alert();
$.ajax("actors.json",{
   dataType: "JSON"
    ,error:function(xhr, status,error){
        alert("error");
        alert(xhr);     //xmlhtttprequest 객체
        alert(status);  //응답상황
        alert(error);   //not found
    }
    ,success:function(result,status,xhr){
        alert("success");
        alert(result);  //서버가 응답해준 객체형태 메세지
        alert(status);  //응답상황
        alert(xhr);     //xmlhttprequest
    }
    });
});

</script>
</body>
</html>

0개의 댓글