简体   繁体   English

SPServices将不会加载

[英]SPServices will not load

In the heading of my page, I have: 在页面的标题中,我有:

<script>
function insureSPServices(callbackFunction)
{
  if($().SPServices == null)
  {
     jQuery.getScript("./scripts/jquery.SPServices-2014.01.js", callbackFunction);
  } else {
      callbackFunction.call(null, "Already Loaded");
  }
}
function populate()
{
alert("SPServices loaded? " + (jQuery.SPServices == undefined ? "NO!!!" : "YES."));
}
</script>
<script type="text/javascript" language="javascript">
  $(document).ready(function()
  {
    alert("jQuery");
    alert("!" + $().SPServices.SPGetCurrentSite() + "!");
alert("jQuery loaded? " + (jQuery == undefined ? "NO!!!" : "YES."));
alert("SPServices loaded? " + (jQuery.SPServices == undefined ? "NO!!!" : "YES."
));
    insureSPServices(populate());
  });
</script>

I get: JQuery YES SPServices NO!!! 我得到: jQuery是SPServices否! SPServices NO!!! SPServices没有!!!

Notes: The two script paths are legitimate. 注意:这两个脚本路径是合法的。

The SPServices script was downloaded from: http://spservices.codeplex.com/downloads/get/786994 可从以下网站下载SPServices脚本: http : //spservices.codeplex.com/downloads/get/786994

The check/init logic is from here: http://devspoint.wordpress.com/2011/01/07/quick-way-to-load-spservices/ 检查/初始化逻辑来自此处: http : //devspoint.wordpress.com/2011/01/07/quick-way-to-load-spservices/

All help appreciated. 所有帮助表示赞赏。

There might be several problems: 可能有几个问题:

  1. The path may not be resolved correctly (sometimes relative urls seem just not to work correctly in SharePoint context) 路径可能无法正确解析(有时相对URL似乎在SharePoint上下文中无法正常工作)
  2. When using jQuery in Javascript within eg a SharePoint webpart try to use jQuery.noConflict() before using the SP-Services. 在SharePoint Webpart之内的Javascript中使用jQuery时,请在使用SP服务之前尝试使用jQuery.noConflict()。 In most cases I had issues with using $ or jQuery because of the already loaded JQuery within SharePoint. 在大多数情况下,由于在SharePoint中已经加载了JQuery,因此在使用$或jQuery时会遇到问题。
  3. When using javascript in SharePoint $(document).ready might cause problems because this doesn´t actually mean that all content is loaded. 在SharePoint $(document).ready中使用javascript时,可能会引起问题,因为这实际上并不意味着所有内容都已加载。 You can try to use _spBodyOnLoadFunctionNames.push("myfunction") instead. 您可以尝试使用_spBodyOnLoadFunctionNames.push(“ myfunction”)。

I also stuck with this problem for couple of hours. 我也坚持了几个小时。 For me the answer was to use jQuery.noConflict() in jQuery declaration. 对我来说,答案是在jQuery声明中使用jQuery.noConflict()。 Like this: 像这样:

<script src="../../myLib/jquery-1.11.3.min.js" type="text/javascript">
jQuery.noConflict();
</script>

When using jQuery within SharePoint Web Part try to use jQuery.noConflict() . 在SharePoint Web部件中使用jQuery时,请尝试使用jQuery.noConflict() In many cases there are issues using $ or jQuery because of the already loaded jQuery within SharePoint. 在许多情况下,由于SharePoint中已经加载了jQuery,因此使用$jQuery出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM