jQuery / jQuery Mobile 에서 json 파싱 방법 > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

jQuery / jQuery Mobile 에서 json 파싱 방법 정보

jQuery jQuery / jQuery Mobile 에서 json 파싱 방법

본문


//이부분은 jQuery Mobile 시에 화면 로딩시 실행하라는 의미 입니다.
$('#화면ID').live('pageshow',function(event, ui){
/* 일반 jQuery일 경우 $(document).ready(function(){ */

//일단 자료를 넣을 div 비워둠.
 $("#목록ul ID").empty();

//Ajax부분(getJSON 으로 쓰기도 함)
 $.ajax({
  type:'POST',

//json 파일 위치
  url: 'url 넣어주세요.',
  dataType: 'json',
  timeout: 10000,
  success: function(data){

// 데이터 목록일 경우의 for 함수
   for(i=0; i<10; i++){

//jQuery Mobile 리스트 썸네일 프레임웍 레이아웃으로 구현시
    document.getElementById("목록ul ID").innerHTML += '<li><img src="'+data[i].img+'.png"><h3>'+data[i].title+'</h3><p>'+data[i].content+'</p></li>';
   }
  },
//에러시 멘트  
 error: function(request, textStatus, errorThrown) {
   alert('error:'+textStatus);
  }
 });
});

JSON 형식을 보면 [{"":""},{"컬럼명":"값"}] 형태일때 data[i].컬럼명 을 쓰시면 됩니다.

추천
0
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로