Php 如何在jquery对话框关闭刷新该页面时显示成功消息

Php 如何在jquery对话框关闭刷新该页面时显示成功消息,php,jquery,Php,Jquery,成功和失败消息出现在上面的对话框中以形成 我需要的是在对话框中显示成功消息,而不是表单详细信息,当用户关闭dialog refreshing test.php页面时,我如何才能做到这一点 test.php <script type="text/javascript"> <!-- var currentOperation = ""; $(function(){ $('#Add').dialog({ autoOpen:

成功和失败消息出现在上面的对话框中以形成 我需要的是在对话框中显示成功消息,而不是表单详细信息,当用户关闭dialog refreshing test.php页面时,我如何才能做到这一点

test.php

<script type="text/javascript">
    <!--
    var currentOperation = "";
    $(function(){
        $('#Add').dialog({
            autoOpen: false,
            width: 600,
            title : 'Add New'
        });
    });
    function openDialog(operation){
        currentOperation = operation; 
        $('#Add').dialog('open');
        $('#Add').html("Loading...");
        $.ajax({
               type: "POST",
               url: "addNewForm.php",                  
               data: "",
               success: function(msg){
                   $('#Add').html(msg);
               },
               error:function(msg){
                     $('#Add').dialog("close"); 
               }               
             });
    }
    function authenticate(){
        $.ajax({
               type: "POST",
               url: "addNew.php",                  
               data: $("#form").serialize(),
               success: function(msg){
                   if(msg=="success")
                   {
                       alert(msg);
                       $('#successful').html(msg);
                   }
                   else
                   {
                       $('#errorMessage').html(msg);
                   }
               },
               error:function(msg){
                    $('#Add').dialog("close"); 
               }               
             });
    }

    //-->
    </script>  

<div style='display: none;' id='Add'></div>
<p><a onclick=openDialog("AddNew") href="#" id="dialog_link"> Add New Details </a></p>

嗯..我不确定我的理解是否正确,但是。。成功后,将消息写入会话,页面刷新后检查该值。若它在那个里,在你们想要的地方展示它,并将它从会话中移除

    <div style="color:red" id="errorMessage"></div>
    <div  id="suceesful">
    <form action="addNew.php" method="POST" id="login_form"  onsubmit = "return false;">
    <table>
        <tr>
            <td align="right">user Name:</td>
            <td align="left"><input type="text" name="userName" /></td>
        </tr>
        <tr>

            <td align="right" colspan="2">
                <input name="addDetails" type="button" id="submit" value="submit" onclick ="javascript:authenticate();" />
            </td>
        </tr>
    </table>
    </form>
    </div>  
try{
require_once ('connect.php');
$username = $_POST ['userName'];
if ($username == NULL) {
        throw new Exception ( "A user name is required" );
}
$db->beginTransaction ();
$sql = $db->query(
            "INSERT INTO users (id,userName)
            VALUES( :p_id, :p_userName)", 
            array( 'p_id' => '', 'p_userName' => $userName)  
            );
$db->commit ();
if($sql)
{
    echo "Sucessfully Added";
} else {
    echo "failed";
}
}
catch (Exception $e)
{
    echo $e->getMessage();
}