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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!