简体   繁体   English

无法弹出jQuery对话框

[英]Can't get the jQuery dialog to popup

I am trying to get the jQuery dialog box to popup up after pressing the "upvote" link here: http://www.problemio.com 我试图在这里单击“ upvote”链接后弹出jQuery对话框: http : //www.problemio.com

(I was working from this example, and then modified it since it didn't work for me: http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/ ) (我正在使用此示例,然后对其进行了修改,因为它对我不起作用: http : //blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog /

Here is the jQuery code I have so far which doesn't work :) 这是到目前为止我无法使用的jQuery代码:)

<script type="text/javascript">
$(document).ready(function() 
{
   var $dialog = $('.dialog')
           .dialog({
               autoOpen: false,
               title: 'Basic Dialog'
           });   

    $('.vote_up').click(function() 
    {        
        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=+';

        $.ajax({
                type: "POST",
                url: "/problems/vote.php",
                dataType: "json",
                data: dataString,
                success: function(data)
                {           
                    // ? :)
                    alert (data);   
                },
                error : function(data) 
                {
                    //alert("ajax error, json: " + data.responseText);
                    errorMessage = data.responseText;

                    if ( errorMessage == "not_logged_in" )
                    {
                        alert ("errr");

                        // Try to create the popup that asks user to log in.
                        //$(this).dialog();
                        //$(".dialog").dialog();
                        $dialog.dialog('open');
                        // prevent the default action, e.g., following a link
                        return false;
                    }
                    else
                    {
                        alert ("not");
                    }

                    //alert(JSON.stringify(data));
                }
            });


        //Return false to prevent page navigation
        return false;
    });

    $('.vote_down').click(function() 
    {
        alert("down");

        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=-';        

        //Return false to prevent page navigation
        return false;
    });    
});
</script>

Above this code I have another jQuery function that also has a documentOnready check. 在此代码上方,我还有另一个jQuery函数,也具有documentOnready检查。 Would that matter? 那会重要吗? Should I make the dialog box code global? 我应该将对话框代码设为全局吗? If so, how do I do that? 如果是这样,我该怎么做?

In any case, how can I get the dialog box to open for me with the setup I have now? 无论如何,如何使用现在的设置为我打开对话框?

Thanks!! 谢谢!!

Changed my jQuery imports to this: 将我的jQuery导入更改为此:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.16/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" />

You need to include the jQuery UI script on your page. 您需要在页面上包括jQuery UI脚本 That's what includes the dialog plugin . 那就是对话框插件

Currently you are only referencing jQuery 1.6.4 in your HTML. 当前,您仅在HTML中引用jQuery 1.6.4。

Change this (at the top within your $(document).ready() ): 更改此设置(在$(document).ready()中的顶部):

   var $dialog = $('.dialog')
           .dialog({
               autoOpen: false,
               title: 'Basic Dialog'
           }); 

to

   var $dialog = $('.dialog');
   $dialog.dialog({
               autoOpen: false,
               title: 'Basic Dialog'
           }); 

And it is okay to have multiple $(document).ready() , they all should run once the dom is loaded 并且可以有多个$(document).ready() ,一旦dom加载,它们都应该运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM