프로그래밍/JavaScipt

javascript ajax로 동적 select box 가져오기

p-a-r-k 2017. 7. 12. 11:45
반응형

2 depth dynamic select box

jquery ajax으로 선택에 따라 달라지는 서브메뉴를 db에서 불러와야했음 ㅎ



html :

	
	

js :

	function fnGetCtgSub(sParam){
		var $target = $("select[name='ctg_sub_name']");
		
		$target.empty();
		if(sParam == ""){
			$target.append("");
			return;
		}

		$.ajax({
			type: "POST",
			url: "/pages/etc/GetCtgSubList.php",
			async: false,
			data:{ P_NO : sParam },
			dataType: "json",
			success: function(jdata) {
				if(jdata.length == 0){
					$target.append("");
				}else{
					$(jdata).each(function(i){
						$target.append("");
					});
				}
			}, error:function(xhr){
				console.log(xhr.responseText);
				alert("지금은 시스템 사정으로 요청하신 작업을 처리할 수 없습니다.\n잠시 후 다시 이용해주세요.");
				return;
			}
		});
	}


반응형