none
resolving $ is not a function when using SP Services RRS feed

  • Question

  • Hi all,

    I need your help on this.
    On the editform of an item, i have added a cEWP and hiddent the default editform webpart. The CEWP calls a html file which references jquery and spservices. The html shows a few fields of the SP List item one among which is a multiline text field called comments where I display all the versions of a comment using  spservices, getversioncollection method, 
    http://sharepoint.stackexchange.com/questions/22958/spservices-to-retrieve-version-history-of-items-in-sharepoint-list-2007


    But this showed $ is undefined for the SPServices. For this I added a 
    var JQ=jQuery.noconflict(true);
    and I was able to use JQ in the the SPServices method. This code was called from the document.ready, e.x.

    $(document).ready(function(){

    GetComments();
    });

    There are buttons on the form which have jquery functionality. All of this was working fine. Now when i moved the code to another environment, I get the error '$ is not a function' inside the button click events. When I comment the GetComments code, the button functionality works. I am not sure how to resolve this as the same code is working in one system but not another. Kindly help.
    Saturday, January 14, 2017 10:48 AM

All replies

  • I was able to reproduce similar situation in script below. Can someone tell me how to fix this?

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
    
    $(document).ready(function(){
    LoadData();
    });
    
    function LoadData()
    {
            $("p").text("jQuery is still working!");
           DisplayComments(); 
    }
    function DisplayComments()
    {
      var j=$.noConflict(true);
      j("p").append("<br>conflict jQuery is still working!");
    }
    function foo()
    {
     $("p").append("<br>jQuery is not recognized here");
    }
    </script>
    </head>
    <body>
    
    <p>This is a paragraph.</p>
    <button onclick='foo()'>Test jQuery</button>
    </body>
    </html>
    

    Saturday, January 14, 2017 3:44 PM
  • Got it working by 
    function DisplayComments()
    {
     //Call SPServices using jQuery().SPServices...
      jQuery("p").append("<br>removed noConflict,used jQuery and jQuery is still working!");
    }


    Sunday, January 15, 2017 5:33 AM
  • Hi,

     

    You could mark your solution as answer, it may help others who has similar.

     

    Best Regards,

    Lee


    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 17, 2017 8:05 AM