添加注释时刷新页面

时间:2014-01-28 21:07:05

标签: jquery coldfusion

目前我随时添加评论。它将注释添加到数据库,但冻结了我所拥有的按钮,因此它们不起作用。虽然如果我刷新页面,他们会再次工作。添加评论后是否有办法让页面刷新。目前以下是我的代码。

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>
            Untitled Document
        </title>

        <cfquery datasource="AccessTest" name="qTest">
            SELECT P.Account, P.Image, P.Image_ID, C.Remarks, C.Users, C.Accounts, C.Date_Time
            FROM PictureDB AS P
            INNER JOIN CommentsDB AS C
            ON C.Image_ID = P.Image_ID
            ORDER BY P.Image_ID
        </cfquery>

        <script src="http://code.jquery.com/jquery-2.0.3.js">

        </script>

        <script>
            $(document).ready(function(){
                  var images = {
                    <cfoutput query="qTest" group="Image_ID">
                        "#qTest.Image_ID#": {
                            "image": "#qTest.Image#",
                            "remarks": [
                            <cfoutput>
                                "#qTest.Users#, #qTest.Date_Time# <br> #qTest.Remarks# <br> </br>",
                            </cfoutput>
                            ]
                        },
                    </cfoutput>
                };
                  $("button").click(function(event){
                    event.preventDefault();
                    var id = $(this).data("id");
                    var src = images[id].image;
                    var desc = images[id].remarks.toString();

                    $("#theImage").attr("src", src).removeClass("hide");
                    $("#theDescription").html(desc).removeClass("hide");
                    });
                });
        </script>
    </head>

    <body>


        <cflayout name="myAccordionLayout" type="accordion" width="600px">

            <cflayoutarea title="Bill Analysis" align="left">
                        <cfoutput query="qTest" group="Account">
                    <button data-id="#qTest.Image_ID#">
                        #qTest.Account#

                    </button>

                </cfoutput> 

                    <cfform name="InsertComments" id="InsertComments">
            <fieldset>
<div id="container">
    <div id="mainContent">


            <textarea name="Remarks" cols="55" rows="4" label="Tour Description"
                                    required="yes" validateat="OnSubmit" message="Please enter your comment here" 
                                    enabled="no">
                        </textarea>
            <input type="text" name="Image_ID" message="Please enter Account Here." 
                                 validateat="onSubmit" required="yes" id="Image_ID" size="10"
                                 maxlength="60">
                        </input>
        <input type="submit" name="insertComments" value="Insert Comments" id="submit">
                        </input>
        </div>
    </div>  
    </fieldset>
    </cfform>
        <cfif IsDefined("form.InsertComments")>

                    <cfquery datasource="AccessTest">
                        INSERT INTO CommentsDB (Remarks, Image_ID, Date_Time )
                        VALUES
                        (<cfqueryparam value="#form.Remarks#" cfsqltype="CF_SQL_LONGVARCHAR">

                        , <cfqueryparam value="#form.Image_ID#" cfsqltype="cf_sql_integer">

                        , <cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">

                        )
                    </cfquery>

            </cfif>


                <img id="theImage" class="hide">
        <div id="theDescription" class="hide">
        </div>
            </cflayoutarea>
            <cflayoutarea title="Operations Analysis">
        Test
            </cflayoutarea>
        </cflayout>
        </body>
</html> 

1 个答案:

答案 0 :(得分:1)

你以前没有发过这个代码吗?

为什么不在执行查询后再执行<cflocation>?这样,用户不会刷新并重新提交表单,它也可以解决您的问题。

<cfif IsDefined("form.InsertComments")>
      <cfquery datasource="AccessTest">
            INSERT INTO CommentsDB (Remarks, Image_ID, Date_Time )
            VALUES
                 (
                    <cfqueryparam value="#form.Remarks#" cfsqltype="CF_SQL_LONGVARCHAR">
                    ,<cfqueryparam value="#form.Image_ID#" cfsqltype="cf_sql_integer">
                    ,<cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">
                 )
      </cfquery>
      <cflocation url="URL OF PAGE" addToken="false" />
</cfif>