• 회원가입
  • 로그인
  • 구글아이디로 로그인

[JSON] JS - JSON - HTML (= 테이블 및 드롭다운 형태로 출력 + 출력개수선택)

JSON은 JS로 쉽게 변환 가능.

JS는 웹페이지에서 HTML 만드는 데 사용 가능. 

 

 

[참고] a.php 세팅 - 아래 좌표 맨 하단 참고

https://homzzang.com/b/js-97?sca=JSON

 

 

HTML Table

 

JSON으로 받은 데이터로 HTML Table 만들기


/b.php 소스 


<p id="demo"></p>


<script>

var obj, dbParam, xmlhttp, myObj, x, txt = "";

obj = { limit: 20 };

dbParam = JSON.stringify(obj);

xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {

  if (this.readyState == 4 && this.status == 200) {

    myObj = JSON.parse(this.responseText);

    txt += "<table border='1'>"

    for (x in myObj) {

      txt += "<tr><td>" + myObj[x].mb_name + "</td></tr>";

    }

    txt += "</table>"    

    document.getElementById("demo").innerHTML = txt;

  }

};

xmlhttp.open("POST", "a.php", true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.send("x=" + dbParam);

</script>

 

 

 

 

HTML 동적 Table - 출력개수 선택

 

/b.php 소스 


<select id="limit_select" onchange="hz(this.value)">

  <option value="">출력 개수</option>

  <option value=1>1</option>

  <option value=2>2</option>

  <option value=3>3</option>

</select>


<p id="demo"></p>


<script>

function hz(sel) {

  var obj, dbParam, xmlhttp, myObj, x, txt = "";

  obj = { limit:sel };

  dbParam = JSON.stringify(obj);

  xmlhttp = new XMLHttpRequest();

  xmlhttp.onreadystatechange = function() {

    if (this.readyState == 4 && this.status == 200) {

      myObj = JSON.parse(this.responseText);

      txt += "<table border='1'>"

      for (x in myObj) {

        txt += "<tr><td>" + myObj[x].mb_name + "</td></tr>";

      }

      txt += "</table>" 

      document.getElementById("demo").innerHTML = txt;

    }

  };

  xmlhttp.open("POST", "a.php", true);

  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

  xmlhttp.send("x=" + dbParam);

}

</script>

 

 

 

 

HTML DropDown List - 특정 데이터 선택 메뉴

 

/b.php 소스 

 

<p id="demo"></p>


<script>

var obj, dbParam, xmlhttp, myObj, x, txt = "";

obj = { limit: 20 };

dbParam = JSON.stringify(obj);

xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {

  if (this.readyState == 4 && this.status == 200) {

    myObj = JSON.parse(this.responseText);

    txt += "<select>"

    for (x in myObj) {

      txt += "<option>" + myObj[x].mb_name;

    }

    txt += "</select>"

    document.getElementById("demo").innerHTML = txt;

  }

};

xmlhttp.open("POST", "a.php", true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.send("x=" + dbParam);

</script>

 



분류 제목
String JS - concat() 메서드 ★ - 문자열결합 (= 문자열합치기 = concat메서드 = 컨캣메서드)
String JS - endsWith() 메서드 - 지정문자열로 끝나는지(=종료) 여부 (IE12이상)
String JS - fromCharCode() 메서드 - 유니코드를 문자열로 변환
String JS - includes() 메서드 ★ - 지정문자열포함여부 (= includes메서드 = 인클루드즈메서드)
String JS - indexOf() 메서드(문자열) ★ - 처음일치문자열위치찾기 (= 문자열포함검사 = 인덱스어브메서…
String JS - lastIndexOf() 메서드(문자열) ★ - 마지막일치문자열위치찾기 (= 문자열포함검사 = 라스…
String JS - localeCompare() 메서드 - 문자열순서비교
String JS - match() 메서드 ★ - 일치하는 문자열 반환 (= match메서드 = 매치메서드) ※ 정규식 …
String JS - repeat() 메서드 - 지정횟수만큼 문자열반복 (= 리피트)
String JS - replace() 메서드(String용) ★ - 문자열 대체 (= replace메서드 = 리플레이스…
String JS - search() 메서드 - 문자열위치찾기 ※ 문자열포함검사
String JS - slice() 메서드 - 문자열 자르기 (= 문자열 일부 추출 = slice메서드 = 슬라이스 메서…
String JS - split() 메서드 - 문자열 쪼개기 (= split메서드 = 스플릿 메서드) ※ 이메일숨기기 (…
String JS - startsWith() 메서드 - 지정문자열로 시작 여부 (IE12이상)
String JS - substr() 메서드 ★ - 문자열 자르기 - 문자열의 특정 위치 이후의 특정 길이 만큼 반환
String JS - substring() 메서드 ★ - 문자열 일부 추출 (= 문자열 자르기 = substring메서드…
String JS - toLocaleLowerCase() 메서드 - 로캘 소문자로 변환
String JS - toLocaleUpperCase() 메서드 - 로캘 대문자로 변환
String JS - toLowerCase() 메서드 - 소문자로변환
String JS - toString() 메서드 (문자열경우) - 문자열타입으로 변경 (= toString메서드 = 투스…
6/67
목록
찾아주셔서 감사합니다. Since 2012