Javascript jQueryUI对话框只工作一次?

Javascript jQueryUI对话框只工作一次?,javascript,php,jquery,mysql,jquery-ui,Javascript,Php,Jquery,Mysql,Jquery Ui,如前所述,我有以下php代码: 编辑:我粘贴了错误的代码,已更正 <?php $posts = new Posts(); foreach($posts->getPosts() as $post){ ?> <div class="post"> <h3><a class="post-link" data-post-id="<?php echo $post['id']; ?>" href="javascript:vo

如前所述,我有以下php代码:

编辑:我粘贴了错误的代码,已更正

<?php
$posts = new Posts();

foreach($posts->getPosts() as $post){ ?>
    <div class="post">
        <h3><a class="post-link" data-post-id="<?php echo $post['id']; ?>" href="javascript:void(0)"><?php echo $post['title']; ?></a></h3>
    </div>

<?php } ?>

<div id="insert-answer" title="Add new idea to post">
<form id="myForm" action="insertidea.php" method="post">
    <fieldset>
        <p><label for="idea">Your idea:</label>
            <input type="text" name="idea" class="idea"</p>
        <p><label for="pic">Have a pic? Paste its URL here! (optional)</label>
            <input type="text" name="pic" class="pic"></p>
        <input type="hidden"class="author" name="author" value="<?php echo $_SESSION['google_data']['id']; ?>" />
        <input type="hidden"class="forpost" name="forpost" value="<?php echo $post['id']; ?>" />
    </fieldset>
</form>
因此,用户应该看到一个帖子列表,每个帖子都有一个链接,弹出一个对话框,该对话框包含一个表单,该表单通过另一个php文件通过post将数据发送到mysql数据库,它工作正常,只是第一次。第二次出现语法错误时,根据firebug,它来自发送到php文件的数组。我怀疑我的对话框功能不完整,发送数据后是否需要“取消设置”任何内容?我将如何做到这一点


非常感谢

您的foreach在表单之前关闭。所以实际上你只有一种形式。也不会在foreachWell之外工作这很尴尬,我粘贴了错误的代码。我指出了发布后清空隐藏作者字段的错误。有没有办法让它保持填充状态?您的foreach将在表单之前关闭。所以实际上你只有一种形式。也不会在foreachWell之外工作这很尴尬,我粘贴了错误的代码。我指出了发布后清空隐藏作者字段的错误。有没有办法让它保持人口稠密?
$( "#insert-answer" ).dialog({
    autoOpen: false,
    modal:true,
    buttons: {
        "Add idea": function() {
            var forpost = $("#insert-answer").data("post-id"),
                author = $("#author").val(),
                idea = $(".idea").val(),
                pic = $(".pic").val();

            $.post('insertidea.php',{
                forpost: forpost, author: author, idea: idea, pic: pic, action:'joined'
            });//End Post

            $("#insert-answer").val('');
            $(".pic").val('');

            $(this).dialog("close");
        },

        Cancel: function() {
            $( this ).dialog( "close" );
        }
    }
});

$( ".post-link" ).on('click', function() {
    var postid = $(this).data("post-id");
    var answer = $("#insert-answer");
    $(answer).data('post-id', postid);
    $(answer).dialog( "open" );
});