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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
7번째 줄: 7번째 줄:
==예시 1: 텍스트 읽기==
==예시 1: 텍스트 읽기==
*예제에서 불러오는 웹페이지: https://rawgit.com/jmnote/test1/master/utf8test.txt
*예제에서 불러오는 웹페이지: https://rawgit.com/jmnote/test1/master/utf8test.txt
<source lang='html'>
<syntaxhighlight lang='html'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
14번째 줄: 14번째 줄:
});
});
</script>
</script>
</source>
</syntaxhighlight>
<jsfiddle height='180'>hqnbgyjp</jsfiddle>
<jsfiddle height='180'>hqnbgyjp</jsfiddle>


20번째 줄: 20번째 줄:
* $.get()은 JSON도 일반문자열로 인식한다.
* $.get()은 JSON도 일반문자열로 인식한다.
* JSON을 제대로 인식하게 하려면 $.getJSON()을 이용해야 함
* 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>
28번째 줄: 28번째 줄:
console.log(data.age); // undefined
console.log(data.age); // undefined
});
});
</script></source>
</script></syntaxhighlight>


==예시 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>
39번째 줄: 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>
49번째 줄: 49번째 줄:
   });
   });
</script>
</script>
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

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 }}