gpt4 book ai didi

javascript - 当我尝试删除日历中的事件时出现 500(内部服务器错误)

转载 作者:行者123 更新时间:2023-12-03 03:54:31 25 4
gpt4 key购买 nike

我正在尝试删除网站完整日历中的一个事件。但是每次我点击按钮不删除时,我都会收到消息未定义,我转到控制台并得到出现以下错误: enter image description here

我尝试根据我的研究添加此脚本:

 $.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})

但仍然遇到同样的错误

我也尝试添加这行代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

但这对 .

没有影响。

这是我的 caledar.blade.php 类:

<!doctype html>
<html lang="{{ config('calendar') }}">
<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<title>Full Calendar</title>

{!! Html::style('vendor2/seguce92/bootstrap/css/bootstrap.min.css') !!}
{!! Html::style('vendor2/seguce92/fullcalendar/fullcalendar.min.css') !!}
{!! Html::style('vendor2/seguce92/bootstrap-datetimepicker/css/bootstrap-material-datetimepicker.css') !!}
{!! Html::style('vendor2/seguce92/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css') !!}

</head>

<div id='app'></div>
<div class='container'></div>
<div class="navbar navbar-inverse" style="color:#fff">
<div class="navbar-inner" >
<!-- Branding Image -->
<div id="app">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
@if (Auth::guest())

@else

@endif
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}

</a>
</div>

<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
&nbsp; @if (Auth::guest())

@else

@endif
<li>
<div class="for-group" style="padding-top:10px;">
<input type="text" id="searching_for" placeholder="Search for a user" style="width: 300px;" class="form-control">

</div>

</li>

</ul>
<a class="navbar-brand" href="{{ url('/front') }}">
{{ config('front', 'Nearby') }}

</a>

<a class="navbar-brand" href="{{ url('/suggest') }}">
{{ config('suggest', 'Suggest Me') }}

</a>

<a class="navbar-brand" href="{{ url('/calendar') }}">
{{ config('calendar', 'Events') }}

</a>

<a class="navbar-brand" href="{{ url('/home') }}">
{{ config('home', 'Home') }}

</a>

<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">

<!-- Authentication Links -->
@if (Auth::guest())

<li><a href="{{ route('login') }}">Login</a></li>
<li><a href="{{ route('register') }}">Register</a></li>

@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>

<ul class="dropdown-menu" role="menu">
<li><a href="{{url('/home')}}"><i class="fa fa-btn fa-cogs"></i>Home</a></li>

<li><a href="{{url('/profile/'.Auth::user()->id)}}"><i class="fa fa-btn fa-user"></i>My Profile</a></li>
<li><a href="{{url('/settings')}}"><i class="fa fa-btn fa-cogs"></i>Settings</a></li>
<li><a href="{{url('/front')}}"><i class="fa fa-btn fa-cogs"></i>Map</a></li>

<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>



<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>







</ul>
</li>
@endif
</ul>
</div>
</div>
</nav>

@yield('content')
</div>
</div>
</div>
{{ Form::open(['route' => 'user.events.store', 'method' => 'post', 'role' => 'form']) }}
<div id="responsive-modal" class="modal fade" tabindex="-1" data-backdrop="static"->

<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Registration of new Event</h4>

</div>

<div class="modal-body">

<div class="form-group">
{{Form::label('title','Title') }}
{{Form::text('title',old('title'),['class' => 'form-control'])}}
</div>

<div class="form-group">
{{Form::label('date_start','Date Start') }}
{{Form::text('date_start',old('date_start'),['class' => 'form-control','readonly'=>'true'])}}
</div>

<div class="form-group">
{{Form::label('time_start','Time Start') }}
{{Form::text('time_start',old('time_start'),['class' => 'form-control'])}}
</div>

<div class="form-group">
{{Form::label('date_end','Time Finish') }}
{{Form::text('date_end',old('date_end'),['class' => 'form-control'])}}
</div>

<div class="form-group">
{{Form::label('color','COLOR') }}
<div class="input-group colorpicker">
{{ Form::text('color',old('color'),['class' => 'form-control']) }}
<span class ="input-group-addon">

<i></i>
</span>
</div>
</div>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
{!! Form::submit('Save',['class' => 'btn-btn-success'])!!}

</div>
</div>
</div>

</div>
{{Form::close()}}
<div id='calendar'></div>


<div id="modal-event" class="modal fade" tabindex="-1" data-backdrop="static"->

<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Details of new Event</h4>

</div>

<div class="modal-body">

<div class="form-group">
{{Form::label('_title','Title') }}
{{Form::text('_title',old('_title'),['class' => 'form-control'])}}
</div>

<div class="form-group">
{{Form::label('_date_start','Date Start') }}
{{Form::text('_date_start',old('_date_start'),['class' => 'form-control','readonly'=>'true'])}}
</div>

<div class="form-group">
{{Form::label('_time_start','Time Start') }}
{{Form::text('_time_start',old('_time_start'),['class' => 'form-control'])}}
</div>

<div class="form-group">
{{Form::label('_date_end','Time Finish') }}
{{Form::text('_date_end',old('_date_end'),['class' => 'form-control'])}}
</div>

<div class="form-group">
{{Form::label('_color','COLOR') }}
<div class="input-group colorpicker">
{{ Form::text('_color',old('_color'),['class' => 'form-control']) }}
<span class ="input-group-addon">

<i></i>
</span>
</div>
</div>
</div>

<div class="modal-footer">
<a id="delete" data-href="{{url('events')}}"data-id="" class="btn btn-danger">Delete</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>


{!! Form::submit('Update',['class' => 'btn btn-success'])!!}

</div>
</div>
</div>

</div>


</body>

{!! Html::script('vendor2/seguce92/jquery.min.js') !!}
{!! Html::script('vendor2/seguce92/bootstrap/js/bootstrap.min.js') !!}
{!! Html::script('vendor2/seguce92/fullcalendar/lib/moment.min.js') !!}
{!! Html::script('vendor2/seguce92/fullcalendar/fullcalendar.min.js') !!}
{!! Html::script('vendor2/seguce92/bootstrap-datetimepicker/js/bootstrap-material-datetimepicker.js') !!}
{!! Html::script('vendor2/seguce92/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js') !!}
<script>

var BASEURL="{{url('/')}}";
$(document).ready(function() {

$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})

$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},

navLinks: true, // can click day/week names to navigate views
editable: true,
selectable:true,
selectHelper:true,

select:function(start){
start = moment(start.format());

$('#date_start').val(start.format('YYYY-MM-DD'));
$('#responsive-modal').modal('show');
},
events: BASEURL+'/events',

eventClick: function(event, jsEvent,view){
var date_start = $.fullCalendar.moment(event.start).format('YYYY-MM-DD')
var time_start = $.fullCalendar.moment(event.start).format('hh:mm:ss');
var date_end = $.fullCalendar.moment(event.start).format('YYYY-MM-DD hh:mm:ss');
$('#modal-event #delete').attr('data-id',event.id);
$('#modal-event #_title').val(event.title);
$('#modal-event #_date_start').val(date_start);
$('#modal-event #_time_start').val(time_start);
$('#modal-event #_date_end').val(date_end);
$('#modal-event #_color').val(event.color);
$('#modal-event').modal('show');

}

});

});

$('.colorpicker').colorpicker();

$('#time_start').bootstrapMaterialDatePicker({

date:false,
shortTime: false,
format: 'HH:mm:ss'
});

$('#date_end').bootstrapMaterialDatePicker({

date:true,
shortTime: false,
format: 'YYYY-MM-DD HH:mm:ss'
});

$('#delete').on('click', function(){
var x = $(this);
var delete_url = x.attr('data-href')+'/'+x.attr('data-id');

$.ajax({
url:delete_url,
type:'Delete',
success: function(result){
alert(result.message);
},
error: function(result){
alert(result.message);
}
});
});

</script>
</html>

网络选项卡: enter image description here

这是我的错误日志(今天的事件):

192.168.1.7 - - [10/Jul/2017:13:19:33 +0100] "GET / HTTP/1.1" 200 2586
192.168.103.1 - - [10/Jul/2017:13:19:52 +0100] "GET / HTTP/1.1" 200 2592
192.168.10.1 - - [10/Jul/2017:13:19:43 +0100] "GET / HTTP/1.1" 200 2590
192.168.56.1 - - [10/Jul/2017:13:19:45 +0100] "GET / HTTP/1.1" 200 2588
192.168.103.1 - - [10/Jul/2017:13:19:50 +0100] "GET / HTTP/1.1" 200 2590
192.168.1.7 - - [10/Jul/2017:13:19:38 +0100] "GET / HTTP/1.1" 200 2588
192.168.10.1 - - [10/Jul/2017:13:19:41 +0100] "GET / HTTP/1.1" 200 2588
192.168.56.1 - - [10/Jul/2017:13:19:47 +0100] "GET / HTTP/1.1" 200 2590
fe80::c18:701:c2b7:3d43 - - [10/Jul/2017:13:19:55 +0100] "GET / HTTP/1.1" 200 2646
fe80::c18:701:c2b7:3d43 - - [10/Jul/2017:13:19:56 +0100] "GET / HTTP/1.1" 200 2648
fe80::1510:b6c4:b641:3086 - - [10/Jul/2017:13:19:58 +0100] "GET / HTTP/1.1" 200 2646
fe80::1510:b6c4:b641:3086 - - [10/Jul/2017:13:19:59 +0100] "GET / HTTP/1.1" 200 2648
fe80::b58d:e8c4:8757:9de3 - - [10/Jul/2017:13:20:01 +0100] "GET / HTTP/1.1" 200 2646
fe80::b58d:e8c4:8757:9de3 - - [10/Jul/2017:13:20:02 +0100] "GET / HTTP/1.1" 200 2648
fe80::d524:23aa:32e3:3027 - - [10/Jul/2017:13:20:04 +0100] "GET / HTTP/1.1" 200 2646
fe80::d524:23aa:32e3:3027 - - [10/Jul/2017:13:20:05 +0100] "GET / HTTP/1.1" 200 2648
fe80::c18:701:c2b7:3d43 - - [10/Jul/2017:13:20:06 +0100] "GET /HNAP1/ HTTP/1.1" 400 444
fe80::1510:b6c4:b641:3086 - - [10/Jul/2017:13:20:06 +0100] "GET /HNAP1/ HTTP/1.1" 400 446
fe80::b58d:e8c4:8757:9de3 - - [10/Jul/2017:13:20:07 +0100] "GET /HNAP1/ HTTP/1.1" 400 444
fe80::d524:23aa:32e3:3027 - - [10/Jul/2017:13:20:07 +0100] "GET /HNAP1/ HTTP/1.1" 400 446
127.0.0.1 - - [10/Jul/2017:14:21:44 +0100] "GET / HTTP/1.1" 200 2584
127.0.0.1 - - [10/Jul/2017:14:21:47 +0100] "GET /favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [10/Jul/2017:14:28:29 +0100] "GET /login HTTP/1.1" 200 5704
127.0.0.1 - - [10/Jul/2017:14:28:34 +0100] "GET /css/app.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:28:34 +0100] "GET /css/style.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:28:34 +0100] "GET /js/app.js HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:29:02 +0100] "POST /login HTTP/1.1" 302 336
127.0.0.1 - - [10/Jul/2017:14:29:07 +0100] "GET /login HTTP/1.1" 200 5966
127.0.0.1 - - [10/Jul/2017:14:30:43 +0100] "POST /login HTTP/1.1" 302 336
127.0.0.1 - - [10/Jul/2017:14:30:44 +0100] "GET /login HTTP/1.1" 200 5966
127.0.0.1 - - [10/Jul/2017:14:30:53 +0100] "POST /login HTTP/1.1" 302 332
127.0.0.1 - - [10/Jul/2017:14:30:54 +0100] "GET /home HTTP/1.1" 200 11741
127.0.0.1 - - [10/Jul/2017:14:30:55 +0100] "GET /status_images/KznUnppb_eventhomepagepicture.jpg HTTP/1.1" 200 22623
127.0.0.1 - - [10/Jul/2017:14:31:01 +0100] "GET /calendar HTTP/1.1" 200 12596
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/bootstrap/css/bootstrap.min.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/fullcalendar/fullcalendar.min.js HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/bootstrap-datetimepicker/css/bootstrap-material-datetimepicker.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/fullcalendar/fullcalendar.min.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/fullcalendar/lib/moment.min.js HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/jquery.min.js HTTP/1.1" 200 84380
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/bootstrap/js/bootstrap.min.js HTTP/1.1" 200 36868
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:02 +0100] "GET /vendor2/seguce92/bootstrap-datetimepicker/js/bootstrap-material-datetimepicker.js HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:31:03 +0100] "GET /events?start=2017-06-25&end=2017-08-06&_=1499693462700 HTTP/1.1" 200 203
127.0.0.1 - - [10/Jul/2017:14:31:08 +0100] "DELETE /events/2 HTTP/1.1" 500 47304
127.0.0.1 - - [10/Jul/2017:14:33:23 +0100] "GET /vendor2/seguce92/bootstrap/css/bootstrap.min.css.map HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:33:23 +0100] "GET /vendor2/seguce92/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css.map HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2017:14:33:23 +0100] "GET /vendor2/seguce92/jquery.min.map HTTP/1.1" 404 33257
127.0.0.1 - - [10/Jul/2017:14:39:57 +0100] "DELETE /events/2 HTTP/1.1" 500 47304
127.0.0.1 - - [10/Jul/2017:14:43:16 +0100] "GET /calendar HTTP/1.1" 200 12596
127.0.0.1 - - [10/Jul/2017:14:43:18 +0100] "GET /vendor2/seguce92/jquery.min.map HTTP/1.1" 404 33257
127.0.0.1 - - [10/Jul/2017:14:43:18 +0100] "GET /events?start=2017-06-25&end=2017-08-06&_=1499694197455 HTTP/1.1" 200 203
127.0.0.1 - - [10/Jul/2017:14:43:22 +0100] "DELETE /events/2 HTTP/1.1" 500 47304
127.0.0.1 - - [10/Jul/2017:14:51:08 +0100] "GET /calendar HTTP/1.1" 200 12596
127.0.0.1 - - [10/Jul/2017:14:51:09 +0100] "GET /vendor2/seguce92/jquery.min.map HTTP/1.1" 404 33257
127.0.0.1 - - [10/Jul/2017:14:51:10 +0100] "GET /events?start=2017-06-25&end=2017-08-06&_=1499694669503 HTTP/1.1" 500 41648
127.0.0.1 - - [10/Jul/2017:15:11:02 +0100] "GET /calendar HTTP/1.1" 200 12596
127.0.0.1 - - [10/Jul/2017:15:11:04 +0100] "GET /vendor2/seguce92/jquery.min.map HTTP/1.1" 404 33257
127.0.0.1 - - [10/Jul/2017:15:11:05 +0100] "GET /events?start=2017-06-25&end=2017-08-06&_=1499695864126 HTTP/1.1" 200 203
127.0.0.1 - - [10/Jul/2017:15:11:09 +0100] "DELETE /events/2 HTTP/1.1" 500 47304
127.0.0.1 - - [10/Jul/2017:15:20:35 +0100] "GET /calendar HTTP/1.1" 200 12596
127.0.0.1 - - [10/Jul/2017:15:20:36 +0100] "GET /vendor2/seguce92/jquery.min.map HTTP/1.1" 404 33257
127.0.0.1 - - [10/Jul/2017:15:20:37 +0100] "GET /events?start=2017-06-25&end=2017-08-06&_=1499696436403 HTTP/1.1" 500 41648
127.0.0.1 - - [10/Jul/2017:15:20:43 +0100] "GET /calendar HTTP/1.1" 200 12596
127.0.0.1 - - [10/Jul/2017:15:20:45 +0100] "GET /vendor2/seguce92/jquery.min.map HTTP/1.1" 404 33257
127.0.0.1 - - [10/Jul/2017:15:20:46 +0100] "GET /events?start=2017-06-25&end=2017-08-06&_=1499696444995 HTTP/1.1" 200 203
127.0.0.1 - - [10/Jul/2017:15:20:56 +0100] "DELETE /events/2 HTTP/1.1" 500 47304

来自 fiddler 的屏幕截图:

enter image description here

错误截图: enter image description here

web.php:

 Route::get('/calendar', function () {
return view('calendar');
});

Route::resource('events', 'EventsController', ['only' => ['index', 'store', 'update', 'destroy']]);

最佳答案

@taha 是在正确的轨道上,但是必须添加隐藏字段,Laravel 不会为你做这件事。大多数浏览器不支持DELETE,因此您需要use method spoofing通过将隐藏字段添加到您的表单中,或者直接添加到 JS 中的 POSTed 数据中,就像您所做的那样:

$.ajax({
url:delete_url,
type:'POST',
data: '_method=DELETE',
success: function(result){
alert(result.message);
},
error: function(result){
alert(result.message);
}
});

另外,请确保您在app/Http/routes.php中设置了相应的删除路由,例如:

Route::delete('/events/{event}', 'Controller@method');

关于javascript - 当我尝试删除日历中的事件时出现 500(内部服务器错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45014177/

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