Solved

My first Javascript and jquery attempt with Sharepoint

Posted on 2016-10-31
7
68 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 16

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 16

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 16

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 16

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

Suggested Solutions

Title # Comments Views Activity
How to position loader with CSS 3 39
JavaScript let vs var 5 26
Hide cell in a table 2 14
Adding Row and Cell on a table 14 20
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

777 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