loadjson

it/ajax 2014. 9. 11. 11:24 Posted by 하얀나다

menu.json

 

{"menuItems":[
 "images/menu_1.png",
 "images/menu_2.png",
 "images/menu_3.png",
 "images/menu_4.png",
 "images/menu_5.png"
 ]
}

 

menu.xml

 

<?xml version="1.0" encoding="utf-8" ?>
<menu>
 <menuitem>
  <img>images/menu_1.png</img>
 </menuitem>
 <menuitem>
  <img>images/menu_2.png</img>
 </menuitem>
 <menuitem>
  <img>images/menu_3.png</img>
 </menuitem>
 <menuitem>
  <img>images/menu_4.png</img>
 </menuitem>
 <menuitem>
  <img>images/menu_5.png</img>
 </menuitem>
</menu>

 

loadjson.html

 

<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title></title>
 <script  type="text/javascript"  src="libs/jquery-1.9.1.min.js"> </script>
 <script>
  
  $(document).ready(function(){
   // ###############################################
   $.getJSON("menu.json",null,parseData);

   alert("전송시작");
  })
  
  function parseData(objInfo){

   var menuItems = objInfo.menuItems;
   alert("메뉴 아이템 갯수는?  "+ menuItems.length);   
  }
 </script>
</head>

<body>
</body>
</html>

 

loadxml,html

 

<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title></title>
 <script  type="text/javascript"  src="libs/jquery-1.9.1.min.js"> </script>
 <script>
  
  $(document).ready(function(){
   // ###############################################
   $.post("menu.xml",null,parseData);

   alert("전송시작");
  })
 
  function parseData(xmlInfo){
   var menuItems = xmlInfo.getElementsByTagName("menuitem");
   
   alert("메뉴 아이템 갯수는?  "+menuItems.length);
  }
  
 </script>
</head>

<body>
</body>
</html>



 

 

'it > ajax' 카테고리의 다른 글

jquery ajax 연동 post 방식  (0) 2014.09.11
jquery ajax 연동 get 방식  (0) 2014.09.11
ajax 디비연동  (0) 2014.09.11
아작스 ajax 서버 주고 받기  (0) 2014.09.11