admin管理员组文章数量:1401509
I'm trying to bring toastr into my application. I've done something very simple:
bundles.Add(new ScriptBundle("~/Content/example-scripts").Include(
"~/Areas/Examples/Scripts/vendor/*.js"
));
Where that folder contains toastr.js. And then in my view:
@Scripts.Render("~/Content/example-scripts")
I see toastr getting loaded in Chrome, yet when I call toastr from my viewmodel:
$(document).ready(function () {
toastr.success('sup');
ko.applyBindings(new ViewModel());
});
I get the following errors:
Uncaught Error: Mismatched anonymous define() module: function ($) {
return (function () {
var version = '2.0.1';
var $container;
var listener;
var toastId = 0;
var toastType = {
error: 'error',
info: 'info',
success: '...<omitted>...ch require.js:166
Uncaught ReferenceError: toastr is not defined sampleVm.js:36
What am I doing wrong?
I'm trying to bring toastr into my application. I've done something very simple:
bundles.Add(new ScriptBundle("~/Content/example-scripts").Include(
"~/Areas/Examples/Scripts/vendor/*.js"
));
Where that folder contains toastr.js. And then in my view:
@Scripts.Render("~/Content/example-scripts")
I see toastr getting loaded in Chrome, yet when I call toastr from my viewmodel:
$(document).ready(function () {
toastr.success('sup');
ko.applyBindings(new ViewModel());
});
I get the following errors:
Uncaught Error: Mismatched anonymous define() module: function ($) {
return (function () {
var version = '2.0.1';
var $container;
var listener;
var toastId = 0;
var toastType = {
error: 'error',
info: 'info',
success: '...<omitted>...ch require.js:166
Uncaught ReferenceError: toastr is not defined sampleVm.js:36
What am I doing wrong?
Share Improve this question asked Feb 28, 2014 at 17:34 SB2055SB2055 12.9k37 gold badges105 silver badges205 bronze badges 6- 1 look at the source on the page and make sure that toastr is being included in the bundle, then make sure that the script where you are trying to reference it is after that call – Matt Bodily Commented Feb 28, 2014 at 17:36
- Thanks @MattBodily. I see toastr.js being loaded, and then after that, my vm that calls it. – SB2055 Commented Feb 28, 2014 at 17:40
- It seems that you using require.js but you are not using it to load toaster.js which leads to this exception... see also: requirejs/docs/errors.html#mismatch – nemesv Commented Feb 28, 2014 at 17:42
- @nemesv - require.js is being used, but not in this part of the app... – SB2055 Commented Feb 28, 2014 at 17:45
- Still it is also included this page otherwise you wouldn't receive this error... If it not needed this page just remove the require.js reference and toaster should work fine. – nemesv Commented Feb 28, 2014 at 17:46
1 Answer
Reset to default 4It seems you are using require.js because the error message is ing from it.
And the Mismatched anonymous define() module
means that toaster.js was defined as an anonymous module but it was not loaded through require.js module loading mechanism.
So there is two solution for this in your case:
- If you are using require.js, use that to load toaster.js
- If it was not intended to use require.js, just remove the reference from your page and toaster.js will load just fine
本文标签: javascripttoastr is undefined when using toastrjsStack Overflow
版权声明:本文标题:javascript - toastr is undefined when using toastr.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744264232a2597869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论