【问题标题】:open jquery dialog from php redirect error从 php 重定向错误打开 jquery 对话框
【发布时间】:2012-10-21 11:38:10
【问题描述】:

我在数据库更新后无法通过重定向打开 jquery 窗口。当页面重定向时,我进行了编码,以便我可以获取值并根据该值打开窗口。下面的例子。

header("Location: http://localhost/sample/users/cp.php?dialog=1");
exit();

在 cp.php 我有以下不触发窗口的代码。但是,如果我更改 autoOpen:true,则窗口会在页面加载时加载。如果有人能指出我的错误,我将不胜感激。谢谢

cp.php

<?php
$dialog = $_GET['dialog'];
if ($dialog ==1)
        {
           echo '<script type="text/javascript"> dialog(); </script>';
        }

?>
<script src="js/jquery-1.3.2.min.js"></script>
<script src="js/ui.dialog.js" type="text/javascript"></script>
<link href="css/redmond/jquery-ui-1.7.3.custom.css" rel="stylesheet" type="text/css" media="all" />

<script type="text/javascript">
  function dialog() {
    $(function() {
        $( "#response1" ).dialog({
            modal: true,
            autoOpen: false,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });


    });
  }
    </script>


 <div style="display:none" id="response1" title="Successfully updated destroy date">
    <p>
        <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
        You have successfully updated your destroy date. You may now close this window. Thank you.
    </p>

</div>

【问题讨论】:

  • 您在声明该函数的脚本之前回显调用 dialog() 的脚本

标签: php jquery dialog


【解决方案1】:

首先,你应该升级JQuery和JQueryUI版本。

这是一个建议:

<script type="text/javascript">
$(function() {
    if(<?php echo ($dialog == 1) ? 'true' : 'false' ; ?>)
    {
        $( "#response1" ).dialog({
            modal: true,
            autoOpen: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    }
});
</script>

这个小提琴解释了如何使用你的代码:http://jsfiddle.net/2bxYW/

【讨论】:

  • 感谢您的回复。但是,它会出错:解析错误:语法错误,第一行出现意外的“
  • 现在我得到:解析错误:语法错误,意外':',期待','或';'在 if 条件下。谢谢
  • 出错:解析错误:语法错误,意外的 T_ENDIF。谢谢
  • 已更新。抱歉,所有这些愚蠢错误的原因是我无法用我的笔记本电脑进行测试......
  • np。我们都去过那里:-) 我现在得到的只是一个简短的空消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-10
  • 1970-01-01
相关资源
最近更新 更多