开发者

jQueryUI - uncaught exception: cannot call methods

开发者 https://www.devze.com 2023-01-18 08:09 出处:网络
I\'m very new to jQuery and trying to run a pretty simple jQueryUI dialog box in my PHP application. In firebug console I get the error:

I'm very new to jQuery and trying to run a pretty simple jQueryUI dialog box in my PHP application. In firebug console I get the error:

uncaught exception: cannot call methods on dialog prior to initialization; attempted to call method 'open'

Here is my code:

$(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        show: "blind",
        hide: "explode"
    });

    $( "#opener" ).live('click',function() {
        $( "#dialog" ).dialog( "open" );
        return false;
    });
});

I did some googling on the error and not much turned up, except that jquery.ui.js is generating the error with:

if ( isMethodCall ) {
    this.each(function() {
        var instance = $.data( this, name );
        if ( !instance ) {
            throw "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'";
        }
...

Any ideas? I appreciate any help on what this error message is and how to resolve it.

UPDATE: I tried commenting out the show/hide options and that did not have any effect on my problem. Below is the HTML:

开发者_StackOverflow中文版
 <div class="demo">

    <div id="dialog" title="Basic dialog">
        <p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>

    <button id="opener">Open Dialog</button>

</div><!-- End demo -->

This HTML is included in a PHP file, which is INCLUDED in another PHP file.


OK, it had to do with the fact that I was putting the dialog DIV on a PHP file that hadn't been loaded yet at the time my JS was loaded. So I moved the DIV for the dialog box up to a higher page, and the button works on any page throughout my app now. I hope this helps someone else.


I was getting the same error. This fixed it for me, taken from http://forum.jquery.com/topic/jquery-ui-model-dialog-close

$(".ui-dialog-content").dialog().dialog("close");


In my case, I use: jQuery UI - v1.9.2, and I have only:

$this.sortable("destroy");

and I get:

Uncaught Error: cannot call methods on sortable prior to initialization; attempted to call method 'destroy'

And I fixed when add the validation:

if ($this.data( "ui-sortable" )) 
{ $this.sortable("destroy"); }


In my case there was a JS conflict with Mootools (classic Joomla, right?). So I went to main.js and changed this line:

$(function () {

to this one:

jQuery(function ($) {


I was having the same error, and the probleme was the order of code !! you must but your javascript after the html code :).

0

精彩评论

暂无评论...
验证码 换一张
取 消