0

I posted this in the general Stack overflow site but this seems like a better place to post a sharepoint question.

I am trying to move a custom web app (contacts list) from sharepoint 2010 to sharepoint 2013. The contact list works by using jQuery to show a name with a picture, and after clicking on the dark gray bar reveals the rest of the contact information like this: https://i.sstatic.net/sFZ1W.jpg

The list works perfectly in sharepoint 2010 but not in 2013. Here is the code that seems to be breaking:

<script type="text/javascript" language="javascript">
jQuery('#' + '<%= firstpane.ClientID %>' + " div.menu_head").click(function () 
{
jQuery(this).css({ backgroundImage: "" }).next("table.menu_body").slideToggle(100).siblings("table.menu_body").slideUp("fast");
jQuery(this).siblings().css({ backgroundImage: "" });
});

</script>

In sharepoint 2010 when the contact bar is clicked, the table of information is shown perfectly. In 2013, the contact bar is shown but when clicked does not toggle. When I run this in developer tools I get an error stating:

in IE: SCRIPT5009: 'jQuery' is undefined

in chrome: Uncaught ReferenceError: jQuery is not defined

If I try and change jQuery to $ then I get the same error but instead it says $ is not defined. I checked the permissions of the jQuery file in sharepoint and it says the file is there and accessible. Does anyone know how to fix this? Thanks!

Roger

2 Answers 2

2

Roger, Looking at the error description it seem to me that jQuery library is not loaded correctly, Can you check your jQuery.min.js file reference. Make sure it is pointing to the current site address.

Also try changing it to following line to see if that works. None of the jQuery script will be executed if your reference is not correct.

Put this code on your page (script editor web part) and see if it executes correctly.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
alert('loaded');
});
</script>
9
  • One of the most common reason for this to fail is that your jQuery references are still pointing to old SP2010 environment, there is nothing in SP2013 that will block your jQuery. Hope this helps Commented May 9, 2014 at 19:34
  • Another possible reason could be that you are loading too much Javascript, make sure that Miniman Dowload Strategy site feature is turned off. Commented May 9, 2014 at 19:34
  • A window popped up that said "loaded", should I try putting in my original code now? Commented May 9, 2014 at 19:48
  • yes, this means jQuery is loaded on this page. Put this same script on the page where you have web part. Comment the alert statement Commented May 9, 2014 at 19:55
  • It worked! The problem I believe was that I didn't properly load in the jQuery library. Thanks for the help! Commented May 9, 2014 at 20:04
1

Not sure where you are storing your js files, but if you are storing them in the LAYOUTS folder you need to reference what hive you are storing them in now. Example:

2010: src="/_layouts/js/jquery-1.11.0.js"

2013: src="/_layouts/15/js/jquery-1.11.0.js"

Hope this helps!

Your Answer

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

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