jquerysharepoint-2013news-ticker

jquery Hide News Ticker if sharepoint annoucement list is empty


I have a news ticker in my sharepoint 2013 plateforme who works well, but when I don't have news the banner still here empty, How can I hide it ? here's my code : jquery.ticker.js and :

<script type="text/javascript"> 
$(document).ready(function() { 
var soapEnv = "soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \  <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>supported_applications</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                               <FieldRef Name='ID' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "path to.../_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    });

    function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() {
              // var liHtml = $(this).attr('ows_ID') +":   " +$(this).attr('ows_Title')+'<br>'; var liHtml = "<li><a href='path to.../Lists/applications/DispForm.aspx?ID=" + $(this).attr('ows_ID') + "'>" + $(this).attr('ows_Title') + "</a></li>";
            $("#tasksUL").append(liHtml);}); }
</script><ul id="tasksUL"/>

Any Suggestions?


Solution

  • Hid the containing html element if count is empty.

     function processResult(xData, status) {
    
    if( $(xData.responseXML).find("z\\:row").length==0)
    {
             $("#tasksUL").hide();
    }
    
            $(xData.responseXML).find("z\\:row").each(function() {
                  // var liHtml = $(this).attr('ows_ID') +":   " +$(this).attr('ows_Title')+'<br>'; var liHtml = "<li><a href='path to.../Lists/applications/DispForm.aspx?ID=" + $(this).attr('ows_ID') + "'>" + $(this).attr('ows_Title') + "</a></li>";
                $("#tasksUL").append(liHtml);}); }