«

»

Jul 08 2011

Print this Post

Adding jQuery+SPServices to a SharePoint Page: Step One, Always

alert(

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");

Alert GetCurrentSite()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>

Permanent link to this article: http://sympmarc.com/2011/07/08/adding-jqueryspservices-to-a-sharepoint-page-step-one-always/

5 comments

1 ping

  1. Tasha

    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!’” ^_~

  2. Prateek Kulkarni

    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.

    1. Marc

      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.

  3. sabin

    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

  4. Webweaver1021

    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.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>