2010-08-04 11 views
0

일부는 내 문제를 밝힐 수 있기를 바랍니다. 기본적으로 특정 DOM 요소가있는 경우에만 코드 블록을 실행하려고합니다. 만약 그렇다면 나는 약간의 비트와 밥을 수행 한 다음 함수를 호출한다. 그러나 함수가 정의되지 않았기 때문에 함수가 범위에 있지 않음을 알립니다. "getFeed();"IF 범위 내 기능 범위

$(document).ready(function() 
     { 
     if ((document.getElementById("view<portlet:namespace/>:editSplash")!= null)) { 
     console.log("notifications scripted started"); 

     // hide loading box/ notify on body load 
     $('.ajaxErrorBox').hide(); 
     $('.loadingNotifications').hide(); 
     $('.notifyWindow').hide(); 
     getFeed(); 

     // set up refresh button for reloading feed 
     $('.refreshFeed').click(function() { 
     $('.notifyWindow').hide(); 
     $('.notifyWindow').empty(); 
     console.log("notifications clicked"); 
     getFeed(); 
     }); 

    // begin ajax call using jquery ajax object 

    function getFeed() 
    { 
    $('.notifyWindow').empty(); 
    console.log("ajax call for feed starting"); 
     $.ajax ({ 
     type: "GET", 
     url: "http://cw-pdevprt-05.tm-gnet.com:10040/notificationsweb/feed?username=uid=<%@ taglib uri="/WEB-INF/tld/engine.tld" prefix="wps" %><wps:user attribute="uid"/>", 
     dataType: "text/xml", 
     timeout: 10000, 
     success: parseXml  
     }); 
     }; 

     // show loading box on start of ajax call 

     $('.notifyWindow').ajaxStart(function() { 
     $('.refreshFeed').hide("fast"); 
     $('.notifyWindow').hide(); 
     $('.ajaxErrorBox').hide(); 
     $('.loadingNotifications').show("fast"); 

     }); 

     // hide loading box after ajax call has stopped 

     $('.notifyWindow').ajaxStop(function() { 
     $('.loadingNotifications').hide("slow"); 
     $('.refreshFeed').show("fast"); 

     }); 

     $('.notifyWindow').ajaxError(function() { 
     $('.loadingNotifications').hide("slow"); 
     $('.ajaxErrorBox').show("fast"); 
     $('.refreshFeed').show("fast"); 
     }); 

    // parse the feed/ xml file and append results to notifications div 

    function parseXml (xml) { 
     console.log("xml parsing begining");   
     if (jQuery.browser.msie) 
     { 
      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
      xmlDoc.loadXML(xml); 
      xml = xmlDoc; 
     } 


    $(xml).find("entry").each(function() 
    { 

    var $item = $(this); 
    var title = $item.find("title").text(); 
    var linkN = $item.find("link").attr("href"); 
    var output = "<a href='" + linkN + "' target='_self'>" + title + "</a><br />"; 
    $(".notifyWindow").append($(output)).show(); 

    }); 
    } 



     } 
else { 
    console.log("notifications not available"); 
    return false; 
} 

}); 

DOM 요소가 난 후 getFeed 기능을 시도하고 전화있는 경우 : 아래 코드는 그러나 그것은 다시 정의되지 않습니다. 누군가가 이것에 대해 밝힐 수 있다면 그것은 크게 감사 할 것입니다.

미리 감사드립니다.

+0

요소의 'id'는'view : editSplash'입니까? 유효한 [이름]이 아닙니다 (http://www.w3.org/TR/html401/types.html#type-name). – kennytm

+0

그것은 유효한 이름입니다. 포틀릿을 사용하여 작업하고 있으며 jsf에서 DOM 요소를 검색하는 데 필요한 이름 공간입니다. 건배 – jonnyhitek

+0

* 다시 정의되지 않은 *로 무엇을 의미합니까? 'getFeed' 함수가 정의되지 않았습니까? –

답변

0

문제 해결 - if 문 외부로 함수를 이동했습니다. 우리는 살고 배우고 :-)

1

그것이 정의되기 전에 getFeed를 호출하는 것처럼 보입니다. 함수 정의 뒤에 if 문을 이동하십시오. 이 동작은 실제로 구현에 따라 다르므로 일부 브라우저는 이러한 방식으로 작동하고 일부 브라우저는 작동하지 않을 수 있습니다.

오, 그리고 진지하게? ID가 view<portlet:namespace/>:editSplash 인가?

+0

예를 들어 jsf 포틀릿을 사용하여 포틀릿 이름 공간을 사용해야하는 dom 요소를 식별 할 수 있습니다. 예 : http://www.liferay.com/community/wiki/-/wiki/Main/Portlet+namespace;jsessionid=C2CD75F96318975D6BC68820A29D0B22.node-1 내 질문에 대답 해 주셔서 감사합니다. 아래에서 볼 수있는 문제를 해결했습니다. if 문 외부의 함수를 범위에 있지 않은 상태로 옮겼습니다. – jonnyhitek

+0

그것은 그 자체로 범위가 아닙니다. 문제를 일으키는 실행 명령입니다. – troelskn