成功:jquery中的函数(数据)永远不会执行


success: function(data) in jquery is never executed

我在jquery函数中执行ajax调用,以便将表单发布到控制器。我检查了所有字段都有正确的值,但

sucess : function(data) {
    alert('it works');
}

没有显示任何内容。这是我的代码:

function add_event() {
    // Vars
    var form_values = $('#addEventForm').serialize();
    // Traitement Ajax
    $.ajax({
        type: 'POST',
        url: '<?php echo site_url()."/public/calendar/addEvent/"; ?>',
        data: form_values,
        success: function(data) {
            // Debug
            alert(data);
            if (data == 'true') {
                $('#addEvent').hide();
                location.reload();
            } else {
                alert("error");
            }
        },
    });
}​

这是我在控制器中的代码:

function addEvent()
{       $this->load->library('gcal');
    // Posts      
    $title = $this->input->post('title');
        $click_date = $this->input->post('start_date'); echo $click_date;
    $date       = explode("-", $click_date);
    $year       = $date[0];  
    $month       = $date[1]; 
    $day        = $date[2]; 
    $date_start = $this->unix_timestamp($year.'-'.$month.'-'.$day);
    // Params
    $params = array(
                        'calendarId'    => 'myriam.gsim@gmail.com',
                        'allday'        => true, 
                        'start'         => $date_start,
                        'end'       => $date_start,
                        'summary'       => $title,
                        'description'   => "this is a test"
                    ); 
       echo 'before insertion';
    // Insertion
         $response = $this->gcal->eventInsert($params);
    echo 'apres insertion';

    if($response)
    {
        echo "true";
    } 
    else
    {
        echo "false";
    }
}

我注意到是$response = $this->gcal->eventInsert($params);导致了错误(我在谷歌api控制台上注册了该应用程序)

有人能帮我吗?

添加一个失败…

例如:

$.ajax({ ..
..
..
success: function(data) {alert(data)},
error:function(request, status, error){// do something with it..}
})

我敢肯定,它正在失败。此外,请检查您的控制台以了解更多信息。