JS/JavaScript

[JQuery] [ajax] 04. ajaxMethod

밍글링글링 2017. 8. 28.
728x90

04_ajaxMethod.html

<meta charset="utf-8" />
<script src="../lib/jquery.js"></script>
<script>
$(function(){
 // Using the core $.ajax() method
 $.ajax({
     // the URL for the request
     url: "data/ajax.json",
  
     // the data to send (will be converted to a query string)
     data: {
         id: 123
     },
  
     // whether this is a POST or GET request
     type: "GET",
  
     // the type of data we expect back
     dataType : "json",
  
     // code to run if the request succeeds;
     // the response is passed to the function
     success: function( json ) {
         $( "<h1/>" ).text( json.title ).appendTo( "body" );
         $( "<div class=\"content\"/>").html( json.html ).appendTo( "body" );
     },
  
     // code to run if the request fails; the raw request and
     // status codes are passed to the function
     error: function( xhr, status, errorThrown ) {
         alert( "Sorry, there was a problem!" );
         console.log( "Error: " + errorThrown );
         console.log( "Status: " + status );
         console.dir( xhr );
     },
  
     // code to run regardless of success or failure
     complete: function( xhr, status ) {
         alert( "The request is complete!" );
     }
 });
});
</script>
 

728x90

'JS > JavaScript' 카테고리의 다른 글

[JSP][HTML][timeleaf] Javascript 전역 함수 사용법  (0) 2018.05.04
[JSP] 파일업로드 로딩 화면 샘플 소스 DEMO  (0) 2018.04.02
[JS] 13. Closure  (0) 2017.08.28
[JS] 12. scope  (0) 2017.08.28
[JS] 11. This  (0) 2017.08.28

댓글