表单提交后使用 JS 或 PHP 重新加载当前页面/URI
免责声明:我是网络开发新手。
我正在使用 CodeIgniter 创建事件日历,当我更新事件(使用 js)时,我需要重新加载当时所在的确切当前页面。到目前为止,我所能做的就是重定向到包含日历类的主控制器,这使我回到当前月份。对于在当前月份以外的其他月份编辑一个事件的人来说,这很糟糕。关于使用/做什么有什么想法吗?非常感谢您的帮助!
控制器:
if ($this->events->update($data))
{
redirect('user/planner');
}
else
{
show_404();
}
视图/表单:
<div class="reveal-modal" id="myModal">
<?php echo form_open('user/planner/update/'.$event->id, 'id="updateForm"'); ?>
<h3><?php echo $event->type ?></h3>
<h4><label for="status">Status</label></h4>
<p><?php echo form_dropdown('status', $status_options, $event->status ) ?></p>
<h4><label for="title">Title</label></h4>
<p><input type="text" id="title" name="title" value="<?php echo $event->title ?>" /></p>
<h4><label for="content">Content</label></h4>
<p><textarea rows="7" id="content" name="content"><?php echo $event->content ?></textarea></p>
<p><?php echo form_submit('submit','Save') ?></p>
<?php echo form_close(); ?>
</div>
JS 正在运行的表单:
$(function() {
$('.event_list li').click( function(e) {
console.log(this.id);
$('#update_view_content').load('http://example.com/user/planner/update/'+this.id,function() {
$('#myModal').reveal();
});
});
$('#updateForm').live('submit', function() {
var data = $('#updateForm').serialize();
var url = $(this).attr('action');
$.post(url, data);
return;
});
});
Disclaimer: I'm new to web development.
I'm creating an event calendar using CodeIgniter, and when I'm updating an event (using js), I need to reload the exact current page that I am on at that moment. So far, all I've been able to do is redirect to the main controller containing the calendar class, which brings me back to the current month. This sucks for someone editing one event on a different month other than the current month. Any ideas on what to use/do? Thanks a lot for all of your help!
Controller:
if ($this->events->update($data))
{
redirect('user/planner');
}
else
{
show_404();
}
View/Form:
<div class="reveal-modal" id="myModal">
<?php echo form_open('user/planner/update/'.$event->id, 'id="updateForm"'); ?>
<h3><?php echo $event->type ?></h3>
<h4><label for="status">Status</label></h4>
<p><?php echo form_dropdown('status', $status_options, $event->status ) ?></p>
<h4><label for="title">Title</label></h4>
<p><input type="text" id="title" name="title" value="<?php echo $event->title ?>" /></p>
<h4><label for="content">Content</label></h4>
<p><textarea rows="7" id="content" name="content"><?php echo $event->content ?></textarea></p>
<p><?php echo form_submit('submit','Save') ?></p>
<?php echo form_close(); ?>
</div>
JS That is running form:
$(function() {
$('.event_list li').click( function(e) {
console.log(this.id);
$('#update_view_content').load('http://example.com/user/planner/update/'+this.id,function() {
$('#myModal').reveal();
});
});
$('#updateForm').live('submit', function() {
var data = $('#updateForm').serialize();
var url = $(this).attr('action');
$.post(url, data);
return;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该像 Jan 所说的那样重新加载 document.location (
document.location.reload()
),但只有在请求成功时才应该这样做,所以你的代码将是这样的:you should reload document.location as Jan said (
document.location.reload()
), but it should be done only when request is success, so your code will be something like this:尝试
insted返回;
Try
insted of return;