$ is not defined


#1

Hello I have this error. I do not see it in console but in terminal. Exception in callback of async function: ReferenceError: $ is not defined. I am using bootstrap and its built in modal which I have called without error on the client using $(".modal").modal.(‘show’). I then call this simple method to insert collection with does work without error in console but in terminal i get exception. Here is the method.

 addThisCampaignName: function(doc){

 check(doc,LoyaltyCampaignNames.simpleSchema()); 
 LoyaltyCampaignNames.insert(doc, function(err, docID) {
          
      if(docID){
         $('.modal').modal('hide');
         toastr.success('Your Campaign Name was added!', 'Success!');
      } else {
        toastr.warning(err,'Error!');
      }
  });

}

Even though the toastr does show and the document is inserted i still get error message in terminal. Two errors to be exact.

1). Exception in callback of async function: ReferenceError: toastr is not defined
2). Exception in callback of async function: ReferenceError: $ is not defined

this script is running in the /libs/ folder and the toaster is not a package but the toaster css and javascript was loaded into /client/plugins/ folder. Any idea what am I doing wrong?


#2

addThisCampaignName is defined with Meteor.methods(), right? In that case, you don’t want to put any client side code in there.
Move the client side stuff, i.e. anything here with toastr and $/jQuery into the code that calls the addThisCampaignName method.

// client/main.js
Meteor.call('addThisCampaignName', doc, function(err, docID) {
          
      if(docID){
         $('.modal').modal('hide');
         toastr.success('Your Campaign Name was added!', 'Success!');
      } else {
        toastr.warning(err,'Error!');
      }
  });

EDIT: And rearrange all parameters passing and returning accordingly. Just copy-pasting my code there will not do the trick.


#3

thank you. i will give that a try.


#4
meteor add jquery