![]()
As a follow up to my prior post Adding jQuery to a SharePoint Page: Step One, Always, here’s another step one, always, for when you are using jQuery+SPServices. Even if you have referenced the jQuery library correctly, you still may not be referencing SPServices correctly.
To make sure that SPServices is referenced correctly, add this line:
alert($().SPServices.SPGetCurrentSite());
right after
$(document).ready(function() {
alert("jQuery");
The first alert will ensure that your jQuery reference is correct. The second will ensure that your SPServices reference is correct, assuming that you see the name of your current site. If you see “undefined” or some value which makes no sense, odds are your reference to SPServices is wrong.
If you get both alerts, you’re past some large percentage of the issues I help with in the SPServices Discussions. The rule of thumb is relatively simple: scripts which depend on other scripts must be referenced after those dependencies. SPServices requires jQuery, so you reference jQuery first and then SPservices. If your dependencies are more complex, consider using a more sophisticated script loader, like the great LABjs from Kyle Simpson (@getify). You can also, of course, use SharePoint’s script loading logic, though I’ve never found that it offers much benefit for the complexity it adds.
Here’s the full simple step one test. Obviously, you’d replace the references with your own paths and filenames.
<script type="text/javascript" language="javascript" src="my_path/jquery-1.6.1.min.js"></script><script type="text/javascript" language="javascript" src="my_path/jquery.SPServices-0.6.2.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
alert("jQuery");
alert($().SPServices.SPGetCurrentSite());
});
</script>
5 comments
1 ping
Tasha
July 11, 2011 at 9:44 am (UTC -4) Link to this comment
Excellent! Thanks for looking out for the little guy as always, Marc- this would have helped me a great deal in my beginnings! Though, I still am partial to “‘Hello, Tasha!’” ^_~
Prateek Kulkarni
November 28, 2011 at 7:30 am (UTC -4) Link to this comment
Hi
In my application i want to check the Unique Project Name from the list when the user enter the Project name in Project TextBox . And this check should be done for the first time of insertion. Please tell me how can i achieve and i am very new to sharepoint . It could be my pleasure if u help me. And i am not getting how to use $().SPServices.SPRequireUnique.
Marc
November 28, 2011 at 8:05 am (UTC -4) Link to this comment
Prateek:
Please post your question in the SPServices Discussions. You should also review the general instructions on the first page of documentation along with the SPRequireUnique doc.
M.
sabin
January 25, 2012 at 10:39 pm (UTC -4) Link to this comment
I am rookie about spservices with jquery. I am trying to get [Hyperlink] column from my list and attach that to color coded calculated field. So that Color Coded lights would act as a link which would redirect user to url entered in [Hyperlink] column.
Can anyone please help me how to start and some logics behind it.
Thank You
Webweaver1021
February 23, 2012 at 3:01 pm (UTC -4) Link to this comment
Is there any particular placeholder to put the script references? I’ve checked them by Ctrl + Click and they all work but the popup still does not fire. I am trying to implement in MOSS 2007.
Пример использования jQuery | Внедрение Sharepoint / ECM
July 15, 2011 at 7:30 am (UTC -4) Link to this comment
[...] http://sympmarc.com/2011/07/08/adding-jqueryspservices-to-a-sharepoint-page-step-one-always/ [...]