0

My program uses jquery.gritter plugin to show error and success messages. In the whole application is working perfectly. But only at one place it is showing "Cannot read property 'add' of undefined" for the below code:

$(".cart").on("click", function(){
        if($("#cartCount").html()==""){
            $.gritter.add({
                title: "Cart",
                text: "Cart is empty", class_name: 'gritter-red',
                fade_in_speed: 100, fade_out_speed: 100,
                sticky: true, time: '2000'
            });
        }
    });

I have this code in header.jsp and the header.jsp is included on the main page. The main page is having the import of jquery.gritter.js.

The main page has other included jsp pages where we are using gritter functionality and they are working fine. I tried by including the gritter plugin inside header.jsp as well but it did not work. My application is a Spring MVC application.

How can this be resolved?

deDishari
  • 187
  • 1
  • 3
  • 11
  • how is this java related? – Stultuske Nov 28 '17 at 12:03
  • Added this tag because it is a Java - Spring MVC application, not a standalone HTML-Jquery application. – deDishari Nov 28 '17 at 12:09
  • well ... no doubt it runs on the web, doesn't mean it should be tagged with www, http or https. the error message points to something going wrong in your javascript/typescript flow, a bit the equivalent of Java's NullPointerException – Stultuske Nov 28 '17 at 12:12
  • The gritter plugin suggests to include the import after Jquery import. Followed the same. Not a problem with $ though, because the if condition is working properly. – deDishari Nov 28 '17 at 12:19
  • Maybe you have import jquery.gritter.js after the the include of header.jsp at main page. Also try to include page like: – gkatiforis Nov 28 '17 at 12:28

0 Answers0