Unable to get property 'SPGetCurrentSite' of undefined or null reference

Feb 12, 2015 at 7:05 PM
Hi! Can someone help me with SPServices please, I can't make it work, I tried on a lot of ways, and even make sure that I can see the script on developer view. It's allways the same error, I now have the script on the master page, and the code on NewForm.aspx. Only the JQuery alert works


$(document).ready(function() {
alert("jQuery");
alert($().SPServices.SPGetCurrentSite());
  });
Coordinator
Feb 12, 2015 at 7:14 PM
Are you referencing the SPServices library in the master page as well? Look at the bottom of the first Documentation page for some tips.

M>
Feb 12, 2015 at 7:43 PM
Yes, I'm using the cdn for it, did ctrl + click to see if the URL was wrong, I noticed now that half of the code if comented, see the img http://i.imgur.com/vTdyKOW.png does this happened to someone before?
Coordinator
Feb 13, 2015 at 4:03 AM
That's the minified version of the library, at least it looks like it.

What's the error you are seeing?

M.
Feb 13, 2015 at 10:12 AM
Yes, it is, I tried with the not min too, and get the same error, here are the errors

http://imgur.com/RJIj4pg,g7iqdR9

http://i.imgur.com/g7iqdR9.png
Coordinator
Feb 13, 2015 at 11:47 AM
It looks like neither jQuery nor SPServices is defined, given those two errors. Check in the developer tools to make sure that they are loading in the page. I'm guessing that the path you're using, while it may be correct in SharePoint Designer, is not correct for the page itself

M.
Feb 13, 2015 at 12:25 PM
This is what I get, does it means that they loads? I can see the code if I click them

http://i.imgur.com/XBKJ8QF.png
Coordinator
Feb 13, 2015 at 12:52 PM
That shows that they are loading, but the errors you posts show they aren't. I'm not sure what's going on.

M.
Feb 13, 2015 at 1:07 PM
I forgot to tell, the JQuery alerts works well, only the SPServices gives me an error, I will post the solution if I can fix it for others with the same problem, thanks for the help Marc!
Coordinator
Feb 13, 2015 at 1:17 PM
It's definitely an issue with the src links to the script file(s).

I just ran your exact same code in a page that has both jQuery and SPServices loaded and both alerts fired:
alert("jQuery");
alert($().SPServices.SPGetCurrentSite());
M.
Feb 13, 2015 at 1:41 PM
In the past, when I see this type of error reported here it is due to multiple versions of jQuery being loaded. SPServices may be getting attached to the "other" jQuery instance.
Did you check wether a jQuery version was already being used before including your own?

Paul
-- sent from mobile
Marked as answer by uhcnamufpy on 2/17/2015 at 3:20 AM
Feb 13, 2015 at 4:40 PM
I did have two versions of jQuery, it was loading 1.10.1 and 1.11.2 fixed that, now I'm with the 1.11.2 version, but still have the same problem, I now have my src like this

http://i.imgur.com/yZJnCjh.png
Coordinator
Feb 13, 2015 at 4:46 PM
Edited Feb 13, 2015 at 4:46 PM
The ../../ is probably your problem. That may be the right path from where the master page sits, but it won't be from the actual pages. Use relative links like this instead:

/sitename/jQuery/jQuery-1.11.2.min.js

Better yet, use a CDN.

M.
Feb 13, 2015 at 5:25 PM
I'm using a cdn now for jQuery and SPServices, the two scritps are loading too, it's still the same, here is what the console shows to me

http://i.imgur.com/eV1zI0F.png
Coordinator
Feb 13, 2015 at 5:28 PM
Can you please show your script references? Not an image; the script tags you have in the page.

M.
Feb 13, 2015 at 6:04 PM
These?

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
Coordinator
Feb 13, 2015 at 8:11 PM
That looks right. You should be able to tell in the developer tools whether the two files are actually loading. At thing point, I think you'll just need to do some more debugging.

One thing you should check: you're specifying https in the src for SPServices. If your SharePoint site isn't running https, you'll get an error.

M.
Feb 13, 2015 at 10:55 PM
Your screen capture showed SPServices script tag in the page before jQuery. If that is accurate, and you truly only have 1 version of jQuery, then there should have been an error when SPServices loaded because jQuery would not be there.
Also, if that was a screen capture of a master page, you may have other issues because you are using relative paths.

Paul
-- sent from mobile
Feb 16, 2015 at 10:43 AM
It finally worked! I needed one line extra line of code, it was "jQuery.noConflict(); ", now it works great!
Thanks for your help!
Coordinator
Feb 16, 2015 at 2:26 PM
You should figure out why you have multiple versions of jQuery loading in the page rather than just papering over it. Perhaps your IT folks are loading it in the master page or something. There's not need for you to load it if it's already available.

M.
Marked as answer by uhcnamufpy on 2/17/2015 at 3:20 AM
Feb 17, 2015 at 10:21 AM
I fixed that now, again, thanks for your help! I don't need to use jQuery.noConflict() now