gpt4 book ai didi

javascript - 错误 : SP. ClientContext().get_current throws uncaught typeError: undefined is not a function

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:42 25 4
gpt4 key购买 nike

我正在关注这个 session 研讨会 http://video.ch9.ms/sessions/spc/2014/SPC261.mp4他们在哪里教你如何创建共享点应用程序

在某些时候我有这个脚本

$(document).ready(function () {

//get context and then username
context = new SP.ClientContext.get_Current();
web = context.get_web();

//get the tasks for the user
getTaskCountForUser();


});

它只会计算任务列表中剩余的任务数。

我在应用程序部分 aspx 文件中包含下一个脚本

<%--<script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>--%>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script src="/_layouts/15/sp.js" type="text/javascript"></script>


<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.runtime.debug.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.debug.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js" type="text/javascript"></script>
<script src="../Scripts/QuickTask.js" type="text/javascript"></script>

似乎一切正常。应用程序部分显示在 SharePoint Online 中,我可以将其包含在主页中,但脚本无法正常工作并在该行中抛出 Uncaught TypeError: undefined is not a function

context = new SP.ClientContext.get_Current();

我试过像这样封闭那个片段:

ExecuteOrDelayUntilScriptLoaded(function () {
//my code above in here

}, "sp.js");

但在那种情况下,第一行会抛出相同的错误。

我错过了什么?我使用我的 MSDN 订阅 Vsual Studio 2013 中的 Sharepoint E3 在线帐户,在视频中,这个人无缝地浏览了它。

谢谢

最佳答案

您的代码中有一些拼写错误,调试 js 文件的链接(不是说这是不正确的,但为什么需要它们?)以及获取 ClientContext 对象时出错。

要修复脚本包含问题,请使用以下脚本标签代替您的:

<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js" ></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js" ></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.min.js" ></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js" ></script>

但主要问题出在这一行:

context = new SP.ClientContext.get_Current();

在这种情况下,您不需要使用 new 关键字,您正在使用 getter 获取上下文对象。应该是:

context = SP.ClientContext.get_current();

还要注意 get_current() 函数的大小写 - current 单词应该从小写字符开始。

关于javascript - 错误 : SP. ClientContext().get_current throws uncaught typeError: undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23575047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com