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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器