SPServices will not load

Charles Barouch picture Charles Barouch · May 13, 2014 · Viewed 8.4k times · Source

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.

Answer

Ben picture Ben · Jul 30, 2014

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.