Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript plug in Noty gives error

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.

like image 964
sinθ Avatar asked Aug 11 '12 16:08

sinθ


People also ask

Why is JavaScript saying my function is not a function?

A TypeError: "x" is not a function occurs when a function is called on an object that does not contain the called function. When calling a built-in function that expects a callback function argument, which does not exist. When the called function is within a scope that is not accessible.

Is not a function error message?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.

Is not identified in jQuery?

You may experience the “jQuery is not defined error” when jQuery is included but not loaded. Make sure that it's loaded by finding the script source and pasting the URL in a new browser or tab. The snippet of text you should look for to find the URL to test.


1 Answers

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.

like image 70
kwakwa Avatar answered Oct 15 '22 19:10

kwakwa