[英]How to redirect to another html page without using window.location?
[英]Write an html text inside a div of the next page after window.location redirect using jquery ajax
有没有办法在调用window.location命令后调用(jquery动作/写一个html文本)到新页面的div?
我试图制作一个ajax表单提交,用户将在提交时重定向到新页面,
在该新页面中,隐藏的div将显示在其中的文本
目前这是我的代码
的script.js
$.ajax({
url:url,
type:'POST',
data:datastr,
success:function(result){
if(result=="duplicate"){
$("#status").attr('class', 'span12 alert alert-error');
$("#status").show();
$("#status").html("<h4><center>Duplicate Username</center></h4>");
$("#dept_name").closest(".control-group").attr('class', 'control-group');
$("#username").closest(".control-group").attr('class', 'control-group error');
$("#password").closest(".control-group").attr('class', 'control-group');
$("#username").focus();
}
else{
$("#dept_name").closest(".control-group").attr('class', 'control-group');
$("#username").closest(".control-group").attr('class', 'control-group');
$("#password").closest(".control-group").attr('class', 'control-group');
window.location = base + 'admin/departments/edit_dept/' + result;
}
}
});
我想让下面的代码块在window.location所在的页面上工作
$("#status").attr('class', 'span12 alert alert-error');
$("#status").show();
$("#status").html("<h4><center>Successfully added Department</center></h4>");
可能吗?
谢谢
您可以使用CI会话闪存数据。
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html
在触发window.location
之前,请在flashdata
设置消息。 在登陆/重定向到页面上,检查flashdata
是否具有值(成功/失败)。 如果是,则显示(或触发js方法以显示)消息。
您可以在window.location中添加一个参数,例如:
window.location = base + 'admin/departments/edit_dept/' + result + '?showMessage=12'
然后在下一页上,有一个jquery脚本,用于查找该参数并显示该消息。 看到这个问题 。
或者你可以在服务器上进行。 但是使用jquery它也适用于静态html。
这是一个补丁,可能需要一些调整。
window.location = base + 'admin/departments/edit_dept/' + result+'/err'; //changed to catchup with the view part
在控制器中:
<?php
if($this->uri->segment(4) == "err"){
$data['err'] = true; #will reflect that we need to show the js in the view
$this->load->view('view', $data);
}
?>
在视图部分:
<?php if(isset($err)){ ?>
<script type="text/javascript">
$("#status").attr('class', 'span12 alert alert-error');
$("#status").show();
$("#status").html("<h4><center>Successfully added Department</center></h4>");
</script>
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.