最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting error "toastr is not a function error" when trying to use toastr - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Dec 19, 2017 at 9:50 klugjo 20.9k10 gold badges64 silver badges81 bronze badges asked Dec 19, 2017 at 9:48 AllramEstAllramEst 1,4494 gold badges28 silver badges55 bronze badges 3
  • Are you including toastr script before this line? – sabithpocker Commented Dec 19, 2017 at 9:49
  • yes. and solved it. Had to declaretoastr like this Command: toastr["success"]("test message", "test"). – AllramEst Commented Dec 19, 2017 at 9:50
  • So you might want to either post an answer to your own question, describing in detail what the problem was and what needed to be done to solve it, or delete your own post. – connexo Commented Dec 19, 2017 at 9:52
Add a comment  | 

3 Answers 3

Reset to default 8

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().

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})

Please use toastr with info, warning,success,error or option.

toastr.info('Are you the 6 fingered man?');
发布评论

评论列表(0)

  1. 暂无评论