douque2016 2013-01-17 11:29
浏览 152
已采纳

在JQuery中打开.dialog的问题

Hey guys so I have a interface where, once a user logs in their info is checked, if the user has not read TOS than the dialog box will open. My issue is, it never opens.

Code:

function run(){
    var url = '/pcg/termsofservice/termsofservice.php';
    showUrlInDialog(url);
}
    function showUrlInDialog(url){
      var tag = $("#dialog-container");
      $.ajax({
        url: url,
        success: function(data) {
          tag.html(data).dialog
          ({
              width: '100%',
                modal: true
          }).dialog('open');
        }
      });
    }
    // if user accepts
    function agree(){
        alert("Handler for .click() called.");
    }
    /******is user declines ******/
    function decline(){

     $("#dialog-container").dialog( 'close' );
     /*****run ajax to kill session of current user and return to login page ******/
      $.ajax({ url: '/PCG/termsofservice/declinedkill.php',
             data: {},
             type: 'post',
             success: function(output) {
                 window.location.replace("/PCG/mainlogin.php");
                      }
    });
    }

PHP check to see if they have not read TOS:

//GET TOS setting if any in place, if so display TOS
$TOS = $_GET['TOS'];

if ($TOS == 0){
        echo '<script type="text/javascript">'
   , 'run();'
   , '</script>';
}

In the javascript code above - "#dialog-container" is only defined if the $TOS variable is 0:

<!-- See if TOS is active, if so add these divs for the overlay -->
    <?php
        echo '<div id="dialog-container">
        </div>';
    ?>

All this works except, nothing displays.

Let me know if you have any idea whats wrong, thanks :)

  • 写回答

4条回答 默认 最新

  • doujia5863 2013-01-17 11:41
    关注

    Looks like you're calling jQuery methods before jQuery is ready. You should have you run() call inside jQuery's document.ready function.

    <script type="text/javascript">
        $(document).ready(function() {
           run();
        });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题