Solved

My first Javascript and jquery attempt with Sharepoint

Posted on 2016-10-31
7
35 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 14

Expert Comment

by:SneekCo
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 14

Accepted Solution

by:
SneekCo 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 14

Expert Comment

by:SneekCo
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 14

Expert Comment

by:SneekCo
ID: 41869486
Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now