Solved

My first Javascript and jquery attempt with Sharepoint

Posted on 2016-10-31
7
75 Views
Last Modified: 2016-11-01
I am trying to modify a copy of the master page for a site.  I added <script src"//code.jquery.com//jquery-3.1.1.min.js" </script> as the last line before </head> then set this copy to default master page but it does not resolve and errors out.

What did I do wrong, or what is the right way to do this?
0
Comment
Question by:lmheimendinger
  • 4
  • 3
7 Comments
 
LVL 17

Expert Comment

by:Walter Curtis
ID: 41867298
Here is what I do, with a reference to where I modeled my reference. Note, I am using a copy of jquery from the SharePoint hive. In order use a CDN, the url will replace the path to the hive. Also note, I have a test function that you would remove once you have confirmed that jquery is working as you want it to.

Reference
http://sympmarc.com/2011/07/08/adding-jqueryspservices-to-a-sharepoint-page-step-one-always/

Test
<script language="javascript" src="/_layouts/LM_jQuery/jquery-current-min.js" type="text/javascript"></script>
<script language="javascript" src="/_layouts/LM_jQuery/jquery.SPServices.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">      
      $(document).ready(function() {
            alert("jQuery");
       alert($().SPServices.SPGetCurrentSite());
       });
</script>

Hope that helps...
0
 

Author Comment

by:lmheimendinger
ID: 41867367
Are just the first two <script> lines needed to pull in jscript and the third to run test?

Let me also ask if /_layouts/LM_Query is where SharePoint makes the .js file available?

Sorry to be a dunce, but even with years of coding outside C# and Java<whatever> this all is fuzzy at first glimpse.
0
 

Author Comment

by:lmheimendinger
ID: 41867368
I tried just the first two <script> lines, set the "seattle" page copy to default master page, and still get this

error
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 17

Accepted Solution

by:
Walter Curtis earned 500 total points
ID: 41867426
Your not a dunce, you know to ask questions!

I guess the first questions needs to be what version of SharePoint are you using. If using SharePoint online, none of this applies, sorry. If using real, I mean on-premise SharePoint, here are a couple of points.

A copy of points, SharePoint does not make jQuery available. The jQuery file(s) will need to be added to your farm by the SharePoint admin, that may be you. Of course you don't have to use the files from your server, you can use them from various sources. That means, you would access the jQuery files from a source on the internet. Your company may have restrictions on accessing the internet outside of the company network. That is something you will need to know or check on.

Here is a breakdown of your code from above;
<script src"//code.jquery.com//jquery-3.1.1.min.js" </script>

Before you get too deep in to making changes, try modifying your code like this:
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>

You may need to change the version of jQuery that you are using.

Try that maybe...
0
 

Author Comment

by:lmheimendinger
ID: 41867434
Should have mentioned it is SP online....
0
 
LVL 17

Expert Comment

by:Walter Curtis
ID: 41867441
It is possible to use jQuery with SharePoint online, but you will need to locate the jquery file somewhere such as the site assets library. I am not sure if SPO has jQuery somewhere that is can be used, but probably not since it is not an official MS process. You should also be able to reference the jQuery file locate at google as shown above, but I don't know that for sure.

Good luck...
0
 
LVL 17

Expert Comment

by:Walter Curtis
ID: 41869486
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question