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

jquery - Javascript plug in Noty gives error - Stack Overflow

programmeradmin1浏览0评论

I have the following javascript code:

function delete_draft(id, name) {
    var text = 'Are you sure you want to delete "' + name + '"?';
    alert(id + name)
    var noty = noty({
        text: text,
        buttons: [
        {addClass: 'btn btn-primary', text: 'Yes', onClick: function($noty) {

            // this = button element
            // $noty = $noty element

            $noty.close();
            $.post('/ajax/drafts/delete', {id:id}, function(data) {
                document.location.reload(true);
            });
        }
        },
        {addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
            $noty.close();
        }
        }
    ]});
}

When I run from the consul delete_draft(6, "this is it") I get this error

TypeError: undefined is not a function
arguments: Array[1]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "called_non_callable"
__proto__: Error

How can I fix this? The website for Noty is / If you think it should work, comment.

I have the following javascript code:

function delete_draft(id, name) {
    var text = 'Are you sure you want to delete "' + name + '"?';
    alert(id + name)
    var noty = noty({
        text: text,
        buttons: [
        {addClass: 'btn btn-primary', text: 'Yes', onClick: function($noty) {

            // this = button element
            // $noty = $noty element

            $noty.close();
            $.post('/ajax/drafts/delete', {id:id}, function(data) {
                document.location.reload(true);
            });
        }
        },
        {addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
            $noty.close();
        }
        }
    ]});
}

When I run from the consul delete_draft(6, "this is it") I get this error

TypeError: undefined is not a function
arguments: Array[1]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "called_non_callable"
__proto__: Error

How can I fix this? The website for Noty is http://needim.github.com/noty/ If you think it should work, comment.

Share Improve this question edited Aug 11, 2012 at 21:26 sinθ asked Aug 11, 2012 at 16:17 sinθsinθ 11.5k26 gold badges88 silver badges123 bronze badges 3
  • What is noty ? in code var noty = noty noty as function is undefined. May be you need var noty = function( ? – Vsevolod Commented Aug 11, 2012 at 21:41
  • @Vsevolod That's why I put a link to the noty site at the bottum – sinθ Commented Aug 12, 2012 at 0:07
  • @"Mike G" I can't open your link :-( How you plug the note.js in you html? – Vsevolod Commented Aug 12, 2012 at 0:25
Add a comment  | 

2 Answers 2

Reset to default 25

I have just come across this problem. It turns out to be because the variable name noty is the same as the exported function name noty.

var n = noty({text: 'testing 123'});

Simply changing the variable name fixes it for me.

In addition to renaming the variable make sure you include the layout js file. The default is top, so if it's not specified in the options you'll need to include noty/layouts/top.js. If you specify any other layouts include the appropriate layout js files.

发布评论

评论列表(0)

  1. 暂无评论