티스토리 툴바


블로그 이미지
누구나 하얀 도화지가 주워진다면, 멋있는 그림을 그리는 걸 상상하곤 합니다. 비록 사람의 도화지는 수채화 같아서 지나온 흔적이 고스란히 남곤 하지만 그것 또한 나이기에 난, 아직 채워지지 않은 공간을 위해 오늘 하루도 멋지게 그려볼까 합니다.
muse'

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
  • 942total
  • 0today
  • 2yesterday
2011/01/26 10:45 HTML5/JQuery/Ajax

# 플라워팀 구현 Tip

include 페이지를 ajax로 처리하기 위해서 .load()를 사용했으나, css가 적용이 안되는 오류가 발생했다. 
혼자서 바둥바둥 해결해 보려했지만 실패.... 결국은 역시 데꾸벅님께서 해결!!

 .load() 사용불가 : HTML5에서는 innerHtml 기능을 제공하지 않고 있다. 대안으로 plugin.js에 정의된 innerShiv를 이용해보자.
innerShiv에서는 innerHtml을 제공하는 브라우져는 innerHTML로 그 외는 appendChild로 처리하고 있다. 
(참고로 resultDataSet 는 HTML형태 이다.)

        /**
         *  JQuery를 이용한 페이지 로딩
         */
        function searchCategoryProducts(val) {
            //불러올 URL 조립
            var urlStr = $("#selViewCategory");
            urlStr = "${pageContext.request.contextPath}/main/include/listByCategory.xhtml?viewCategoryId="+val;
            // 삽입할 페이지 호출
            // $("#inc_area").load(urlStr, {}, function(){});  --> 사용불가  
            $.get(urlStr,{},function(resultDataSet,statusTxt,xhr){
             if(statusTxt=="success"){
              $("#inc_area").html( $(innerShiv(resultDataSet,false)) );
             }
            });
        }



# plugin.js에 정의된 innerShiv

/**
 * HTML5 innerHTML Problem
 * @see http://jdbartlett.github.com/innershiv/
 */
window.innerShiv = (function() {
 var d, r;

 return function(h, u) {
  if (!d) {
   d = document.createElement('div');
   r = document.createDocumentFragment();
   /*@cc_on d.style.display = 'none';@*/
  }

  var e = d.cloneNode(true);
  /*@cc_on document.body.appendChild(e);@*/
  e.innerHTML = h.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  /*@cc_on document.body.removeChild(e);@*/

  if (u === false) return e.childNodes;

  var f = r.cloneNode(true), i = e.childNodes.length;
  while (i--) f.appendChild(e.firstChild);

  return f;
 }
}());

저작자 표시 비영리 변경 금지
posted by muse'