none
SharePoint 2013-Jquery Error-"Uncaught TypeError: Cannot read property 'each' of undefined" RRS feed

  • Question

  • Hi,

    I am getting error while executing below code and image

    error-Uncaught TypeError: $ is not a function


    <script type="text/javascript">

    $(document).ready(function() {
      var sPath = window.location.pathname;
      var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
      var isOnlyReader=isUserInGroup('',__zurichReaderID,false);

    if I change $(document to Jquery(document) than It shows error in interaction.js with below code and image

    Error-Uncaught TypeError: Cannot read property 'each' of undefined

    if(viewFields != null && viewFields.length > 0){
    result.append('<viewFields><ViewFields xmlns="">');
    $.each(viewFields, function(idx, field){
    result.append('<FieldRef Name="' + field + '"/>');
    });
    result.append('</ViewFields></viewFields>');
    }

    


    Vishal Goyal



    • Edited by MS_21212 Wednesday, January 4, 2017 10:21 AM
    Wednesday, January 4, 2017 7:31 AM

All replies

  • The $ in your code refers to jQuery. Make sure that you have included jQuery in your code and that it is loaded before your code executes.

    Alternatively you could use a for loop if all you need is $.each from jQuery. 

    Wednesday, January 4, 2017 7:38 AM
  • Hi Vishal,

    Any update?

    As Tanmay's reply please refer to the jQuery library before your JavaScript code.

    Like this:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    	//your custom code
    });
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 5, 2017 7:12 AM
    Moderator
  • Hi Dennis,

    Jquery is already included still it's throwing error.


    Vishal Goyal


    • Edited by MS_21212 Monday, January 9, 2017 12:47 PM
    Monday, January 9, 2017 12:04 PM
  • Hi,

    Please check whether you have multiple jQuery library included or not.

    Or check whether you can access the external network or not(Open IE browser and enter //code.jquery.com/jquery-3.1.0.min.js ).

    Or create a new web part page and add the following code into a content editor web part in this web part page.

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    	alert("Test jQuery");
    });
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Tuesday, January 10, 2017 2:37 AM
    Moderator
  • 1-No There are no multiple jquery library on page and this page also have "Bamboo Calendar Plus Webpart"

    2-External network is accessible

    3-Yes this code is working in new webpart


    Vishal Goyal



    • Edited by MS_21212 Wednesday, January 11, 2017 12:42 PM
    Wednesday, January 11, 2017 12:18 PM
  • Hi Dennis,

    Can you please suggest anything on it?


    Vishal Goyal

    Tuesday, January 24, 2017 11:53 AM
  • Hi,

    How is the JQuery referred or this JS file containing your custom code is referred in the web part? Is it a content editor web part -> where you you are linking a text file containing the custom JS file or directly pasting the custom code with reference?

    Are you using script editor to refer the JS file?

    Can you also try downloading the JQuery reference and upload the file in Site Assets  -> then try referring it in the custom JS. If you have already done this, make sure the path to the JQuery is referred properly.


    Cheers,
    Maruthu
    P.S. : Please click the 'Mark as Answer' button if a post solves your problem! :)
    Explore the SharePoint

    Tuesday, January 24, 2017 12:27 PM
  • Hi Vishal,

    Please check whether you have enabled Minimal Download Strategy (MDS) feature or not.

    Or I suggest you provide more details about how to reproduce this issue, others would get easier to research on it.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, January 25, 2017 1:27 AM
    Moderator