Solved

My first Javascript and jquery attempt with Sharepoint

Posted on 2016-10-31
7
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 18

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

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 18

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 18

Expert Comment

by:Walter Curtis
ID: 41869486
Thanks
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

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 …
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
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)
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…

690 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