如何在回调中使用ajax $ .post()?

时间:2019-04-24 13:14:31

标签: ajax laravel fullcalendar

我正在尝试在'eventDrop'的回调中使用Ajax

这是我使用的代码行:

$.post('{{ route('update_event_ajax') }}', data);

但是添加时,日历不再显示。

这是我的FullCalendar脚本:

$(document).ready(function(){
    $('#calendar-NcAT6P42').fullCalendar( //calendars options...
        ,"eventDrop":
        function(event) {
            $('#event_id').val(event.id);
            $('#event_title').val(event.title);
            $('#event_footnote').val(event.footnote);
            $('#event_id_team').val(event.id_team);
            $('#event_id_customer').val(event.id_customer);
            $('#event_title').val(event.title);
            $('#event_start_date').val(moment(event.start).format('YYYY-MM-DD HH:mm:ss'));
            $('#event_end_date').val(moment(event.end).format('YYYY-MM-DD HH:mm:ss'));
            var data = {
                _token: '{{ csrf_token() }}',
                event_id: $('#event_id').val(),
                event_title: $('#event_title').val(),
                event_start_date: $('#event_start_date').val(),
                event_end_date: $('#event_end_date').val(),
            };
            $.post('{{ route('update_event_ajax') }}', data);
        },
        "events": ...);
});

我也尝试过$.ajax(...),但遇到了同样的问题

我认为我的Ajax不在正确的位置?但是我应该放在哪里?

预先感谢

编辑: 我正在使用Laravel 5.0和Laravel 5 Full Calendar Helper(https://github.com/maddhatter/laravel-fullcalendar

1 个答案:

答案 0 :(得分:0)

刀片语法不能在外部Javascript文件中使用。

我通过在视图中添加以下行来解决了问题:

 try {
   const data = await client.invoke(params).promise();
   console.log('Lambda invoked!');
   console.log('Success Case');
   console.log(data.Payload);
   return data.Payload;
 } catch (err) {
   console.log('Fail Case');
   console.log(err, err.stack);
   throw err;
 }

然后以这种方式使用它:

window['ajax_event_url'] = "{{ route('update_event_ajax') }}";
相关问题