您需要
1。异步发布表单(不使用AJAX重新加载页面)。2.成功发送数据后,请执行dom操作。
我建议使用jquery进行AJAX发布。
这里是使用jquery的示例代码:-
$('#guest_details').load('?p=guest_details.html');
$('#first_start').load('?p=first_start.html')
function ajaxPostForm()
{
$.post('guest_details.php',
function(data) {
//Dom manipulation
$('#guest_details').hide('slow');
$('#first_start').SlideUp('slow')
});
}
并且您在guest_details.html
中的html表单必须类似于:-
<form method="POST" id="guest"> <!-- Some cell here --> <a onclick="ajaxPostForm();" class="button" id="first_start"> <span> <?php echo $button_submit;?> </span> </a> </Form>
上面给出的$ .post是一个非常基本的AJAX帖子。您可以按照Jquery Post中的说明添加更多功能。此外,如果您想发布整个表格,可以参考jQuery Form Plugin
更新我想这次我更了解您的问题。在您的更新中,您说的是这个]->
默认情况下,guest_details.html是显示,并且first_start.html隐藏将这些部分称为
guest_details
和first_start
会更有意义,因为guest_details.html
可能意味着您可能已经在另一个窗口中打开的页面guest_details.html
。[无论如何,我确定您是指页面
process.html
内的部分,因为您使用了jQuery.load()
。让我们分别将first_start.html
和guest_details.html
分别称为first_start
和guest_details
部分。根据您的更新,您的意思是:-
初始状态
显示了guest_details
部分,并隐藏了first_start
案例/情况
提交guest_details
部分中的表单后,隐藏guest_details
部分并显示first_start
部分。在隐藏guest_details
并显示first_start
的状态下,可以单击first_start
上的按钮,然后单击guest_details
部分。在隐藏一个部分而显示另一个部分的这些状态期间,重新加载/刷新页面应保留状态。
如果上面是完整的场景,则代码如下:-
<script> <! - initiateSections(<?php echo $this->session->data['display_state']; ?>); //state can have "display_first_start" or "display_guest_details" function initiateSections(state) { $('#guest_details').load('?p=guest_details.html'); $('#first_start').load('?p=first_start.html') if(state == "display_first_start") { displayFirstStart(); } else {//If chosen or by default displayGuestDetails(); } } function ajaxPostGuestDetails() { $.post('guest_details.php', //In this post request - set $this->session->data['display_state'] = 'display_first_start'; in php function(data) { //Dom manipulation displayFirstStart(); }); } function ajaxPostFirstStart() { $.post('first_start.php', //In this post request - set $this->session->data['display_state'] = 'display_guest_details'; function(data) { //Dom manipulation displayGuestDetails(); }); } function displayGuestDetails() { $('#first_start').hide('slow'); $('#guest_details').slideUp('slow'); } function displayFirstStart() { $('#guest_details').hide('slow'); $('#first_start').slideUp('slow'); } -> </Script>