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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度