Вопрос

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!!! SPServices NO!!!

Notes: The two script paths are legitimate.

The SPServices script was downloaded from: 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/

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)
  2. When using jQuery in Javascript within e.g. a SharePoint webpart try to use jQuery.noConflict() before using the SP-Services. In most cases I had issues with using $ or jQuery because of the already loaded JQuery within SharePoint.
  3. When using javascript in SharePoint $(document).ready might cause problems because this doesn´t actually mean that all content is loaded. You can try to use _spBodyOnLoadFunctionNames.push("myfunction") instead.

Другие советы

I also stuck with this problem for couple of hours. For me the answer was to use jQuery.noConflict() in jQuery declaration. 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(). In many cases there are issues using $ or jQuery because of the already loaded jQuery within SharePoint.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top