drm30963 2013-02-24 11:22
浏览 54
已采纳

在ajax提交的表单提交到预览表单后模拟后退按钮

I have a multi-part form where the flow of the data is:

  1. Answer the form, SUBMIT (via ajax post)
    • jQuery Form and CodeIgniter validation echoed if present
  2. Preview the answers from the form
    • Choices: Cancel, Edit, Commit to database

The three choices are submit buttons with unique names in the preview form. My Commit to database process is finished, while I have difficulty in doing the Cancel and Edit. My current method for the three are (inside the controller):

function preview_form_redirect() 
{
  if ( isset($_POST['submit-form']) ) {
    $this->send_to_database();
  } else if ( isset($_POST['edit-form']) ) {
    // return to form with all answers intact
  } else { // CANCEL FORM
    redirect('accounts');
  }
} // END preview_form_redirect() 

My plan for the Edit option is to simulate back button because I'm sure the data and DOM will be intact.

I know my methods for the two are not perfect but I am stuck and do not know what other methods to simulate the two. Are there possible and compatible ways to do the two for my setup?

  • 写回答

2条回答 默认 最新

  • duanlvxi8652 2013-02-24 11:48
    关注

    You have to do it with Javascript. You can use this library that uses the html5 push state, or html fragments if your browser does not fully support the HTML5 history API: https://github.com/browserstate/History.js/

    When the user clicks on edit button, do something like this: History.pushState({state:1}, "State 1", "?state=1");

    and register an event on the back button: History.Adapter.bind(window,'popstate',function(){ //remove the editable elements from your page });

    Hope it helps.

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

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line