"JQuery $.get()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 3명의 중간 판 13개는 보이지 않습니다)
6번째 줄: 6번째 줄:


==예시 1: 텍스트 읽기==
==예시 1: 텍스트 읽기==
*예제: http://zetawiki.com/ex/jquery/jquery_get_txt.html
*예제에서 불러오는 웹페이지: https://rawgit.com/jmnote/test1/master/utf8test.txt
*예제에서 불러오는 웹페이지: http://zetawiki.com/ex/txt/utf8test.txt
<syntaxhighlight lang='html'>
<source lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
$.get("http://zetawiki.com/ex/txt/utf8test.txt", function(data){
$.get("https://rawgit.com/jmnote/test1/master/utf8test.txt", function(data){
document.write(data);
document.write(data);
});
});
</script>
</script>
</source>
</syntaxhighlight>
<jsfiddle height='180'>hqnbgyjp</jsfiddle>


==예시 2: JSON 읽기==
==예시 2: JSON도 문자열로 인식됨==
*예제: http://zetawiki.com/ex/jquery/jquery_get_json.html
* $.get()은 JSON도 일반문자열로 인식한다.
*예제에서 불러오는 웹페이지: http://zetawiki.com/ex/json/whowhen.json
* JSON을 제대로 인식하게 하려면 $.getJSON()을 이용해야 함
<source lang='html5'>
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
$.get( "/ex/json/whowhen.json", function( data ) {
$.get( "//raw.githubusercontent.com/jmnote/test1/master/john1.json", function( data ) {
document.write( "data: " + data );
console.log(data); // {"firstName":"John","lastName":"Smith","isAlive":true,"age":27}
document.write( "data.name: " + data.name );
console.log(data.firstName); // undefined
document.write( "data.time: " + data.time );
console.log(data.age); // undefined
});
});
// data: [object Object]
</script></syntaxhighlight>
// data.name: John
// data.time: 2pm
</script>
</source>


==예시 3: 파라미터 보내기==
==예시 3: 파라미터 보내기==
<source lang='html5'>
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
43번째 줄: 39번째 줄:
   });
   });
</script>
</script>
</source>
</syntaxhighlight>
<source lang='html5'>
{{소스헤더|배열 보내기}}
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
$.get( "/ex/php/greet.php", { names: ["한놈", "두시기"] } )
$.get( "/ex/php/greet.php", { "names[]": ["한놈", "두시기"] } )
   .done(function( data ) {
   .done(function( data ) {
     document.write( "data: " + data );
     document.write( "data: " + data );
   });
   });
</script>
</script>
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[jQuery $.getJSON()]]
*[[jQuery $.post()]]
*[[jQuery $.post()]]
*[[jQuery $.ajax()]]
*[[jQuery $.ajax()]]
60번째 줄: 58번째 줄:
*[[AJAX]]
*[[AJAX]]


==참고 자료==
==참고==
*http://api.jquery.com/jquery.get/
*http://api.jquery.com/jquery.get/


[[분류: jQuery]]
[[분류: jQuery Ajax]]

2020년 11월 2일 (월) 02:52 기준 최신판

  다른 뜻에 대해서는 jQuery .get() 문서를 참조하십시오.

1 개요[ | ]

jQuery.get()
$.get()

2 예시 1: 텍스트 읽기[ | ]

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$.get("https://rawgit.com/jmnote/test1/master/utf8test.txt", function(data){
	document.write(data);
});
</script>

3 예시 2: JSON도 문자열로 인식됨[ | ]

  • $.get()은 JSON도 일반문자열로 인식한다.
  • JSON을 제대로 인식하게 하려면 $.getJSON()을 이용해야 함
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$.get( "//raw.githubusercontent.com/jmnote/test1/master/john1.json", function( data ) {
	console.log(data); // {"firstName":"John","lastName":"Smith","isAlive":true,"age":27}
	console.log(data.firstName); // undefined
	console.log(data.age); // undefined
});
</script>

4 예시 3: 파라미터 보내기[ | ]

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$.get( "/ex/php/greet.php", { name: "한놈", time: "14:00" } )
  .done(function( data ) {
    document.write( "data: " + data );
  });
</script>
배열 보내기
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$.get( "/ex/php/greet.php", { "names[]": ["한놈", "두시기"] } )
  .done(function( data ) {
    document.write( "data: " + data );
  });
</script>

5 같이 보기[ | ]

6 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}