1

I have placed the jquery library script in the layouts folder on my server:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\CustomScripts

for what ever reason, I cannot get a simple script to run. I have tried every combination I can think of:

<SharePoint:ScriptLink ID="jqueryScriptLink" Localizable="false" runat="server" Name="/_layouts/CustomScripts/jquery-1.11.1.min.js"></SharePoint:ScriptLink>

<SharePoint:ScriptLink ID="jqueryScriptLink" Localizable="false" runat="server" Name="/CustomScripts/jquery-1.11.1.min.js"></SharePoint:ScriptLink>

<script src="/CustomScripts/jquery-1.11.1.min.js"></script>

<script src="/_layouts/CustomScripts/jquery-1.11.1.min.js"></script>

But none seem to load the jquery library. I placed a simple alert in the document ready function:

$(document).ready(function() { 
alert('hello'),
} 

and it isn't working. Is there something in SP or on the server that needs to be done before you can call a custom script from this location? I have tried also to navigate to the script URL:

https://mysharepointinstance/_layouts/CustomScripts/jquery-1.11.1.min.js

and

https://mysharepointinstance/CustomScripts/jquery-1.11.1.min.js

Again, no dice. It says webpage not found.

Any help is appreciated

7
  • try to add type= text/javascript to script import element
    – Nk SP
    Sep 15, 2014 at 14:17
  • tried it but the same thing Sep 15, 2014 at 14:26
  • You can import jquery using this: <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    – Nk SP
    Sep 15, 2014 at 14:27
  • Try this: <SharePoint:ScriptLink ID="jqueryScriptLink" Localizable="false" runat="server" Name="CustomScripts/jquery-1.11.1.min.js"></SharePoint:ScriptLink>
    – Aanchal
    Sep 15, 2014 at 14:27
  • How many application servers?
    – Nk SP
    Sep 15, 2014 at 14:29

2 Answers 2

0

Do you have more that one web front end server in your SharePoint environment?

2
  • yes, two. I am going to copy the script folder right now Sep 15, 2014 at 14:32
  • DOH! Stupid oversight. It works now after adding it to both WFEs. Thank you and Nk SP Sep 15, 2014 at 14:34
0

I had a similar issue once. What helped me is placing the js-File in the SiteAssets and referring it from there. What also helped was using jQuery instead of $ in front of every jQuery command and using

_spBodyOnLoadFunctionNames.push("MyFunctionName");
function MyFunctionName()
 {
 // Code
 }

to make sure all the other js-Files were loaded before executing your code.
Reference:
http://chrisfleischhacker.wordpress.com/2013/04/30/adding-javascript-to-execute-on-sharepoint-pages-body-onload-event/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.