使用响应JSON.parse

时间:2016-12-01 20:31:16

标签: javascript json laravel-5.3

我的错误是:

Uncaught SyntaxError: Unexpected token H in JSON at position 0

我正在尝试在laravel 5.3中创建一个日历,但我在控制台中有一个json响应的错误,在json和javascript我是新的,日历是一个例子,我正在尝试调整laravel。出现这个错误的地方就是这个部分:

$('#calendar').fullCalendar({
        events: JSON.parse(json_events),
        //events: [{"id":"14","title":"New Event","start":"2015-01-24T16:00:00+04:00","allDay":false}],
        utc: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        droppable: true, 
        slotDuration: '00:30:00',
        eventReceive: function(event){
            var title = event.title;
            var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
            $.ajax({
                url: '{{url('calendarController')}}',
                data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone,
                type: 'GET',
                dataType: 'json',
                success: function(response){
                    event.id = response.eventid;
                    $('#calendar').fullCalendar('updateEvent',event);
                },
                error: function(e){
                    console.log(e.responseText);

                }
            });
            $('#calendar').fullCalendar('updateEvent',event);
            console.log(event);
        },
        eventDrop: function(event, delta, revertFunc) {
            var title = event.title;
            var start = event.start.format();
            var end = (event.end == null) ? start : event.end.format();
            $.ajax({
                url: '{{url('calendarController')}}',
                data: 'type=resetdate&title='+title+'&start='+start+'&end='+end+'&eventid='+event.id,
                type: 'GET',
                dataType: 'json',
                success: function(response){
                    if(response.status != 'success')                            
                    revertFunc();
                },
                error: function(e){                     
                    revertFunc();
                    alert('Error processing your request: '+e.responseText);
                }
            });
        },
        eventClick: function(event, jsEvent, view) {
            console.log(event.id);
              var title = prompt('Event Title:', event.title, { buttons: { Ok: true, Cancel: false} });
              if (title){
                  event.title = title;
                  console.log('type=changetitle&title='+title+'&eventid='+event.id);
                  $.ajax({
                        url: '{{url('calendarController')}}',
                        data: 'type=changetitle&title='+title+'&eventid='+event.id,
                        type: 'GET',
                        dataType: 'json',
                        success: function(response){    
                            if(response.status == 'success')                            
                                $('#calendar').fullCalendar('updateEvent',event);
                        },
                        error: function(e){
                            alert('Error processing your request: '+e.responseText);
                        }
                    });
              }
        },
        eventResize: function(event, delta, revertFunc) {
            console.log(event);
            var title = event.title;
            var end = event.end.format();
            var start = event.start.format();
            $.ajax({
                url: '{{url('calendarController')}}',
                data: 'type=resetdate&title='+title+'&start='+start+'&end='+end+'&eventid='+event.id,
                type: 'GET',
                dataType: 'json',
                success: function(response){
                    if(response.status != 'success')                            
                    revertFunc();
                },
                error: function(e){                     
                    revertFunc();
                    alert('Error processing your request: '+e.responseText);
                }
            });
        },
        eventDragStop: function (event, jsEvent, ui, view) {
            if (isElemOverDiv()) {
                var con = confirm('Are you sure to delete this event permanently?');
                if(con == true) {
                    $.ajax({
                        url: '{{url('calendarController')}}',
                        data: 'type=remove&eventid='+event.id,
                        type: 'GET',
                        dataType: 'json',
                        success: function(response){
                            console.log(response);
                            if(response.status == 'success'){
                                $('#calendar').fullCalendar('removeEvents');
                                getFreshEvents();
                            }
                        },
                        error: function(e){ 
                            alert('Error processing your request: '+e.responseText);
                        }
                    });
                }   
            }
        }
    });

如果有人能给我一个认真的回应很多帮助,我是javascript世界的新手

1 个答案:

答案 0 :(得分:1)

检查开发者控制台/网络选项卡以查看实际响应。然后复制并验证它。我很确定服务器响应不是你想象的那样。