Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

My first Javascript and jquery attempt with Sharepoint

Posted on 2016-10-31
7
Medium Priority
?
166 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 20

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 20

Accepted Solution

by:
Walter Curtis earned 2000 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 20

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 20

Expert Comment

by:Walter Curtis
ID: 41869486
Thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

618 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