gpt4 book ai didi

javascript - Laravel + jquery 对话框在发布后重定向(+fullcalendar)

转载 作者:行者123 更新时间:2023-11-30 16:52:25 24 4
gpt4 key购买 nike

我有一个 jquery 对话框,当单击全日历实例中的单个事件时,它的事件会动态更改,如下所示:

$('#calendar').fullCalendar({
//calendar options here
events: 'getlogs',
eventClick: function(calEvent, jsEvent, view) {
//POPUPCODE START
$.ajax({
url: 'getlog',
data: { id: calEvent.id},
dataType: "json",
success: function(data)
{
//set your values in the edit fields here
}
});
$('#logid').val(calEvent.id);
$("#editdeletediv").load().dialog(
{ //Set options for the dialog here
title: 'Edit/Delete log',
modal: true,
autoResize:true,
maxWidth: 600,
minWidth: 500,
buttons: {
Delete: function(){
$.ajax({
url: 'removelog',
type: "POST",
data: { id: calEvent.id },
dataType: "json"
});
},
Save: function(){
}
}
});

//POPUPCODE END

}
});

然后我在我的 laravel routes.php 中有一条路由,它将我使用删除按钮所做的帖子路由到正确的 Controller ,如下所示:

Route::post('removelog/','CalendarController@removeLog');

Controller 中的函数是这样的:

public function removeLog(){            
$id = Input::get('id');
DB::table('time_logs')->where('id', '=', $id)->delete();
}

现在,这一切都很完美,但是有一个缺点。当我单击对话框上的删除按钮时,它不会关闭对话框(我知道该怎么做,不用担心),但是当我添加关闭对话框的功能时,它仍会显示我之前删除的事件。因此我想刷新我的页面(因为当我这样做时,事件已经消失,因为它们是从我的“getlogs”呈现并直接从数据库读取的)所以它不再显示已经删除的事件,我试过有几件事可以让它发挥作用:

在我添加的删除按钮的 jquery 对话框函数中

 window.location.reload and later location.reload

这确实会重新加载我的页面,但是,它以某种方式中断了我对删除功能的发布。

在我的 Controller 中我添加了:

return Redirect::route('calendar');

返回到日历页面,这并没有重定向我,但帖子仍然有效,所以至少它没有破坏任何东西

我也试过:

return Redirect::back();

因为这对我创建日志的其他帖子有效(这里的区别是该帖子是使用表单提交创建的),这也不起作用

我想知道是否有人知道如何在不更改太多代码的情况下使用我当前的设置实现这一点(我花了很长时间才让一切正常工作并记录我是如何做到的,我不会不想重写任何一个)

最佳答案

好的,所以首先尝试使用 DELETE 进行删除请求,但这对功能无关紧要。

在你的 Controller 中:

public function removeLog(){            
$id = Input::get('id');
DB::table('time_logs')->where('id', '=', $id)->delete();

return Response::json(URL::route('calendar'), 200);
}

在你的 Jquery 中

$("#editdeletediv").load().dialog(
{ //Set options for the dialog here
title: 'Edit/Delete log',
modal: true,
autoResize:true,
maxWidth: 600,
minWidth: 500,
buttons: {
Delete: function(){
$.ajax({
url: 'removelog',
type: "POST",
data: { id: calEvent.id },
dataType: "json",
success: function(response){
location.href = response;
}
});
},
Save: function(){
}
}
});

关于javascript - Laravel + jquery 对话框在发布后重定向(+fullcalendar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30320476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com