ajaxjson.html 부분 

<!DOCTYPE html>


<html>


<head>


<script src="http://code.jquery.com/jquery-latest.min.js"></script>


<script>


$(document).ready(function(){


jQuery.ajax({


type:"post",


url: "./arrayjson.html",//"./test.html",


data:"name=junho",


dataType:"JSON",


success: function(data){


//alert(data);



/* var items =[]; */


$.each(data, function(){


//alert(this["name"]);


// 한줄은 되는데 배열은 오류가 난다 



alert(this.id);


alert(this.name);


alert(this.price); 

alert(this.description); 


/* items.push(val);


alert(val);

 */

});


},


complete: function(data){



},


error:function(xhr, status , error){


alert("에러발생");


}



})


})




</script>






<meta charset="EUC-KR">


<title>Insert title here</title>


</head>


<body>




</body>


</html>









arrayjson.html 부분 

[

  {

    "id": "1",

    "name": "레몬",

    "price": " 3000",

    "description": "레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다."

  },

  {

    "id": "2",

    "name": "키위",

    "price": " 2000",

    "description": "비타민C가 매우 풍부하다. 다이에트와 미용에도 매우 좋다."

  },

  {

    "id": "3",

    "name": "블루베리",

    "price": " 5000",

    "description": "블루베리에 포함된 anthocyanin(안토시아닌)은 눈피로에 효과가 있다."

  },

  {

    "id": "4",

    "name": "체리",

    "price": " 5000",

    "description": "체리는 맛이 단 성분이 많고 피로회복에 잘 듣는다."

  },

  {

    "id": "5",

    "name": "메론",

    "price": " 5000",

    "description": "메론에는 비타민A와 칼륨이 많이 포함되어 있다."

  },

  {

    "id": "6",

    "name": "수박",

    "price": "15000",

    "description": "수분이 풍부한 과일이다."

  } 

]



'jquery, ajax' 카테고리의 다른 글

자바스크립트 제이쿼리 this  (0) 2016.01.28
jquery change()  (0) 2015.12.28
다중 셀렉터 다중 css처리  (0) 2015.11.16
ajax를 쓰는 목적  (0) 2015.09.23
ajax를 이용해서 json 배열 받기 성공  (0) 2015.04.07
Posted by 이상욱1
,