This project has moved and is read-only. For the latest updates, please go here.

$().SPServices Undefined

Oct 24, 2013 at 11:53 PM
Edited Oct 24, 2013 at 11:54 PM
I've a baseline script file I use when starting any new file for scripting that has worked on dozens of pages, but today for some reason isn't sufficient.
<SharePoint:ScriptLink runat="server" Name="SP.js" Localizable="false" OnDemand="False" LoadAfterUI="True"></SharePoint:ScriptLink>
<script type="text/javascript" src="http://{ServerName}/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://{ServerName}/jquery.SPServices-2013.01.min.js"></script>



<script type="text/javascript">

    $(document).ready(function() {
        ExecuteOrDelayUntilScriptLoaded(function () {
            //Enhance the save feature to update non-directly editable features
            //e.g. look-up RCM, Purchaser, and Budget data for project.
        }, "sp.js");

Chrome keeps throwing:
Uncaught TypeError: Cannot call method 'SPGetCurrentSite' of undefined
I've verified the file is actually present, as is made apparent by the same inclusion files' usage on several other pages.

Any idea why SPServices would appear to not be ready or initialized?

Thanks in advance.
Oct 25, 2013 at 4:47 AM
Edited Oct 25, 2013 at 4:48 AM
The only thing I see that's unusual is your inclusion of the ExecuteOrDelayUntilScriptLoaded function inside the $(document).ready(). That's unnecessary.

I'd check in the development tools to see if the .js files are actually loaded. It could be that http://{ServerName}/ isn't evaluating correctly.

I'd just use this:
<script type="text/javascript" src="/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/jquery.SPServices-2013.01.min.js"></script>
but the path doesn't look right.

Oct 25, 2013 at 3:58 PM
Edited Oct 25, 2013 at 4:58 PM
Thanks for the quick response., Marc.

Removed the ExecuteOrDelayUntilScriptLoaded for testing. Why wouldn't it be necessary? I've had instances where SP objects were coming back undefined unless I waited for this script (SP.js) to finish loading. To my understanding $(document).ready() only waits for the DOM, but doesn't care so much about script file inclusions.

http://{ServerName}/ is just shorthand for When planning to work with SPServices, I just copy the necessary includes from a text file script baseline to ensure a consistent starting point. The Network tab of Chrome Developer Tools is giving jquery.SPServices-2013.01.min.js a 304 (Not Modified) message on GET. I reviewed other pages with the same inclusion files and the message was the same across the board, but on the other pages SPServices was initializing as expected.

I swapped out the SPServices local source with the CDN: //, and it posted a 200 message, but I still received the same error.

Appreciate the assistance.

Little more info:
I'm overriding the default forms for a list object per Mark Rackley's post:

Planning to have the user populate only a few fields, and attach SPServices functions to go look-up other field data on save.
Oct 26, 2013 at 6:27 PM
Although the file might be present at the time you are looking at it in the Developer tools, I wonder if for some reason the script (SPServices) is taking a little while to load... and thus when you execute your code above, it may not be fully initialized... Try this snippet of code with some additional console.log() statements, and let's see what comes out in the console:
    console.log("$ version:" + $.fn.jquery);
    console.log("window.jQuery version:" + window.jQuery.fn.jquery);
    $(document).ready(function() {
        ExecuteOrDelayUntilScriptLoaded(function () {
            console.log("SPServices loaded? = " + ($.fn.SPServices ? "YES" : "NO") );
            //Enhance the save feature to update non-directly editable features
            //e.g. look-up RCM, Purchaser, and Budget data for project.
        }, "sp.js");
Also, any chance you may have multiple version of jQuery being loaded on the page? The code above will hopefully surface that... :)

Marked as answer by SP_Joe on 10/29/2013 at 3:53 PM
Oct 28, 2013 at 5:29 PM
Edited Oct 28, 2013 at 5:41 PM
jQuery is referenced twice on the page in separate CEWP's. Once in the Form Override CEWP (per Mark Rackley's linked post above), and once in the Display Override for the edit form in question. Removing the local reference causes jQuery to become undefined leading me to believe that the CEWP's are scoping the inclusion to the file/web part in question.

I plugged in the console logs and received:
$ version:1.7.2
window.jQuery version:1.7.2
SPServices loaded? = NO
My first assumption was that SPServices was not loading for some reason, and I tried nesting another ExecuteOrDelayUntilScriptLoaded, but I'm not sure that the function is intended to be nested; especially since when this is done, the script in the nested Delay does not execute and there are no error messages. I was out on Friday, but was thinking maybe I could chain the scripts being loaded by a Promise object. However I hadn't really looked into it yet.

Thanks for lending a hand Paul.
Oct 29, 2013 at 12:53 AM
How is SPServices being included into the page? If a strait script tag into the head section, and your code is after that, it should work. Right click the page and view source, find the line for SPServices and see where it is with relation to your code. The order should be jQuery, SPServices, then your code.

The additional console logs, above tells you that SPServices is not loaded. That's what you should focus on.

Good luck.


Paul T

Oct 29, 2013 at 7:24 AM
Hi there,

My two cents: make sure jquery is not loaded AGAIN after SPServices. That way it would redefine the default $.fn without SPServices.
Marked as answer by SP_Joe on 10/29/2013 at 3:52 PM
Oct 29, 2013 at 11:51 PM
Edited Oct 30, 2013 at 10:45 PM

I think you were onto something there. Since jQuery had to be referenced in each CEWP, it may be that there was some conflict with the $.fn definition. Paul also mentioned this possibility above, but I just didn't catch it then, or note that there would be a conflict.

I moved the SPServices inclusion to the CEWP responsible for hiding the default form's fields and formatting the subsequent HTML and SPServices suddenly started initializing properly.

Now I just need to figure out why the code in:

...isn't functioning.

UPDATE: The above function doesn't seem to like jQuery 1.9.1. No errors thrown, but the code within the function just doesn't get called.

Thanks everyone.