douhan9619 2013-07-26 17:58
浏览 129
已采纳

保存为草稿然后更新草稿?

I have a form with few fields. Now on clicking a button "save as draft", the ajax call will go and the poplulated fields will be stored in the database.

But when the user clicks on "save as draft" again, then this time the previous field should be updated and not a new field be created.

So I thought some remedy

-. Making a hidden field and load it with unique number when the page is loaded and also store it in SESSION variable.

And after comparing the unique number with the session variable, if the number is same then update the field in sql or else create a new field in sql.

Is the above solution ok or people use different one?

  • 写回答

3条回答 默认 最新

  • duan0504 2013-07-26 18:10
    关注

    Why not, on the first Ajax call to 'save draft' retrieve back some very simple JSON such as

    { field_id: 1 }
    

    And then save that save that value either in the DOM by placing it in an input, or better - just store it in a variable. You could then check for this variable's existence on subsequent draft / final saves and change your Ajax post to account for it. You could just have an additional Boolean column in your table such as final which tracks the stage of the post. From the server side perspective, you could easily get the value of the MySQL insert by calling MySQLi's insert_id() method e.g.

    A really nice additional touch might also involve using the pushState method to update the URL (e.g. to index.php?draft=1). That way, even if the user clicked the back button, they could go back to the correct page, and you could pull their saved data for them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 Ubuntu20.04无法连接GitHub
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥30 C++行情软件的tick数据如何高效的合成K线