¾È±Ô °øºÎ¹æ

Javascript & JQuery & CSS > JSONÆÄÀÏ Àоî¿À±â1 - getJSON()

µî·ÏÀÏ : 2017-07-14 17:03 Á¶È¸¼ö : 53,353

¹®¹ýÀº .post()¿Í ºñ½ÁÇÏ´Ù.

.ajax()¸Þ¼­µåÀÇ ´ÜÃàÇ¥±âÀ̸ç, ¸î °¡Áö ¸Å°³º¯¼ö°¡ ¼ÂÆÃµÈ °ÍÀÌ´Ù.

¾Æ·¡ ¼Ò½º¸¦ Å×½ºÆ® ÇØ º¸»ï.
 
	data.asp ÆÄÀϳ»¿ë
	-------------------------------------
	<% If request("abc")="A" Then %>
	[
		{
			"Num" : "1",
			"Name" : "È«±æµ¿"
		},
		{
			"Num": "2",
			"Name": "¹éµÎ»ê"
		}
	]
	<% End If %>

	<% If request("abc")="B" Then %>
	[
		{
			"Num" : "11",
			"Name" : "È«±æµ¿1"
		},
		{
			"Num": "22",
			"Name": "¹éµÎ»ê1"
		}
	]
	<% End If %>



	--------------------------------------------
	test.html ÆÄÀϳ»¿ë
	---------------------------------------------
	$("#btn").click(function() {

		$.getJSON('data.asp?abc=A', {format: 'json'}, function(data) {
			
			//ÆгΠ³»¿ëÀ» ºñ¿î´Ù.
			$('#pnlDisplay').empty();

			var table = "<table border='1'><tr><td>À妽º</td><td>¹øÈ£</td><td>À̸§</td></tr>";

			$.each(data, function(index, entry) {
				table += "<tr>";
				table += "<td>" + index + "</td>";
				table += "<td>" + entry.Num + "</td>";
				table += "<td>" + entry.Name + "</td>";


				table += "</tr>";
			});

			table += "</table>";
		
			$('#pnlDisplay').append(table); //Æгο¡ Ãß°¡Çϱâ

		});

	});

	

$.getJSON('data.asp?abc=A', {format: 'json'}, function(data) {
});

getJSON()À» ÀÌ¿ëÇÏ¿© data.asp ÆÄÀÏ¿¡ Á¢¼ÓÇÑ´Ù

$.getJSON(url, Datatype, function())

ÇüŸ¦ °¡Áö°í ÀÖ´Ù. 

url : Àü¼Û¹ÞÀ» URL ÀÌ´Ù.
Datatype : Àü¼Û¹Þ´Â µ¥ÀÌÅÍÇüÀ» ¶æÇÑ´Ù. (json)
function() : ½ÇÇàÇÑ ÇÔ¼öÀÌ´Ù.
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.