【问题标题】:jQuery ".cycle is not a function" error - follow-up from http://stackoverflow.com/questions/1586998/jQuery“.cycle 不是函数”错误 - 来自 http://stackoverflow.com/questions/1586998/ 的跟进
【发布时间】:2009-10-20 04:31:40
【问题描述】:

所以我正在尝试实施我在上一个问题 (SharePoint SOAP GetListItems VS jQuery - Need some advice on how to use Ajax to cycle through Custom List items as well as Ajax refresh the list contents) 中向我建议的解决方案。我想使用此处找到的循环库:http://malsup.com/jquery/cycle2/ 循环浏览我使用自定义 SharePoint 列表中的行填充的 DIV 的内容。我正在创建的 html 似乎是有效的,但是当我尝试运行下面的循环代码时,我得到:

Error: $("#tasksUL").cycle is not a function
Source File: http://ourdomain.net/Pages/Default.aspx
Line: 426 

这是我在内容编辑器 Web 部件中屏蔽的代码:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="/SiteCollectionDocuments/jquery.timers-1.0.0.js"></script>
<script type="text/javascript" src="/SiteCollectionDocuments/jquery.cycle.all.2.72.js"></script>
<script type="text/javascript">

$(document).ready(function() {

// Create the SOAP request        
// NOTE: we need to be able to display list attachments to users, hence the addition of the
// <queryOptions> element, which necessitated the addition of the <query> element

var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>testlist</listName><viewFields><ViewFields><FieldRef Name='Title' /><FieldRef Name='Body' /><FieldRef Name='ID' /><FieldRef Name='Attachments' /></ViewFields> </viewFields><query><Query /></query><queryOptions><QueryOptions><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls></QueryOptions></queryOptions></GetListItems></soapenv:Body></soapenv:Envelope>";

// call this SOAP request every 20 seconds
$("#tasksUL").everyTime(20000,function(i){
    // our basic SOAP code to hammer the Lists web service
    $.ajax({
    url: "http://ourdomain.net/_vti_bin/lists.asmx",
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    error: printError,
    complete: processResult,
    contentType: "text/xml; charset=\"utf-8\""
    });
  });
});

// basic error display that will pop out SOAP errors, very useful!
function printError(XMLHttpRequest, textStatus, errorThrown)
{
  alert("There was an error: " + errorThrown + " " + textStatus);
  alert(XMLHttpRequest.responseText);
}

// main method that will cycle through the SoAP response nodes
function processResult(xData, status) 
{
    var liHtml = "";
  $(xData.responseXML).find("z\\:row").each(function() 
  {
    // resets display element
    $("#tasksUL").empty();

    // gets attachments array - if there is more than one attachment,
    // they get seperated by semi-colons in the response
    // they look like this natively (just an example):
    // ows_Attachments = ";#http://server/Lists/Announcements/Attachments/2/test.txt;
    // #http://server/Lists/Announcements/Attachments/2/UIP_Setup.log;#"

        var mySplitResult = $(this).attr("ows_Attachments").split(";");
    // set up storage for later display of images
    var notice_images = "";

    // processes attachments - please forgive the kludge!  
    for(i = 0; i < mySplitResult.length; i++)
    {
        // check to see the proper link URL gets chosen
        if (i % 2 != 0 && i != 0)
        {
            // strips out pound sign
            mySplitResult[i] = mySplitResult[i].replace("#", "");

            // (possibly redundant) check to make sure element isn't simply a pound sign  
            if (mySplitResult[i] != "#")
            {
                // adds an img tag to an output container
                notice_images = notice_images + "<img src='" + mySplitResult[i] + "' border='0' align='right' style='float:right;' /><br />"; 
            }
        }
    }

    // create final output for printing
    liHtml = liHtml + "<div><h3>" + $(this).attr("ows_Title") + "</h3><p>" + notice_images + $(this).attr("ows_Body") + "</p></div>";
  });

    // assign output to DIV tags
  $("#tasksUL").html(liHtml);
}
</script>

<script type="text/javascript">
$(document).ready(function() {
    $('#tasksUL').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
});
</script>

<div id="tasksUL">&nbsp;</div>

代码按预期启动,但我想知道关于 Cycle 函数我做错了什么......我已经尝试显式链接到上面包含的所有 JavaScript 文件,我可以在浏览器中访问他们没有问题。为了正确使用这个库,我是否需要为 #tasksUL 实际定义 CSS?代码中有什么明显的东西需要我打脸吗?谢谢!

【问题讨论】:

  • 您确定已加载 Cycle 插件 (malsup.com/jquery/cycle)?
  • 绝对!上面代码中的第三行 JS 是一个实际上工作正常的包含...我可能需要其他文件吗?

标签: jquery ajax sharepoint soap cycle


【解决方案1】:

你从哪里得到 jquery.cycle...js?

至少来自jQuery Cycle Plugin homepage 的压缩文件似乎在文件名的末尾有奇怪的附加字符。当我解压它时,我的文件被称为 jquery.cycle.all.min.js_ 而不是 jquery.cycle.all.min.js

【讨论】:

  • 我最终从同一个存档中的 example.html 文件中使用的地址中获取了该文件,因为我的 WinRAR 客户端无法正确解压缩我从下载的存档中的一些 js 文件上面的地址。 example.html 文件似乎工作得很好,所以我想如果我下载它使用的 JS 文件我会很好。我现在想知道,它是否可能因为我的 DIV 容器开始时没有任何内容而失败?直到 20 秒过去,它才会被填满。另外,如果我使用 .html 方法填充我的 DIV,那真的会破坏 DIV 吗?
【解决方案2】:

实际上,任何人都无法知道这一点,失败的原因是有人安装了一个旧的网站集 jQuery 包,并且不能很好地与 jCycle 配合使用。一旦我在集合上停用该功能,重新启动 IIS 并刷新页面,一切正常。作为一个额外的步骤,我将最新的完整版本的 jQuery 下载到一个文档库中并链接到它而不是 Google 托管的脚本版本。所以我现在使用的所有 js 都存在于网站集中。

我能够弄清楚 jQuery 的冲突版本,但使用 Firebug 的控制台和脚本调试器。我不得不将调试器设置为停止所有错误,但出现的第一个错误是引用站点集合 jQuery 包,而不是我包含的 Google 代码。这就是我回答我自己的问题的原因。那里还有其他可怜的混蛋在做 SharePoint 开发,考虑到 FireFox 对 IE 和所有软件的支持程度,他们可能不会想到使用 FireFox 来测试他们的 SP 安装。

感谢所有阅读并回答/评论的人!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 2017-05-06
    • 1970-01-01
    • 2011-08-31
    相关资源
    最近更新 更多