Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error "toastr is not a function error" when trying to use toastr

I want to use toastr to notify the user. I have followed this guide to set it up. But I get the error message: Uncaught TypeError: toastr is not a function. I have looked at the network tab and the files are loading properly. Tried with a cdn to be sure. But no luck. This is how I tried to use it:

    toastr('Are you the 6 fingered man?');

As in the demo. Any suggestions about what I am doing wrong?

like image 399
AllramEst Avatar asked Dec 13 '22 19:12

AllramEst


2 Answers

According to the documentation you linked, it should be used like this:

toastr.info('Are you the 6 fingered man?')

You forgot to call the function info().

like image 112
tobiso Avatar answered Dec 17 '22 22:12

tobiso


You need to use toastr functions as per below.

See documentation

// Display a warning toast, with no title
toastr.warning('My name is Inigo Montoya. You killed my father, prepare to die!')

// Display a success toast, with a title
toastr.success('Have fun storming the castle!', 'Miracle Max Says')

// Display an error toast, with a title
toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')

// Immediately remove current toasts without using animation
toastr.remove()

// Remove current toasts using animation
toastr.clear()

// Override global options
toastr.success('We do have the Kapua suite available.', 'Turtle Bay Resort', {timeOut: 5000})
like image 42
Shalitha Suranga Avatar answered Dec 18 '22 00:12

Shalitha Suranga