简体   繁体   English

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

[英]success: function(data) in jquery is never executed

I do an ajax call in jquery function in order to post a form to the controller. 我在jquery函数中执行ajax调用,以便将表单发布到控制器。 I checked that all the fields have the right value, but 我检查了所有字段的值是否正确,但是

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

doesn't show anything.Here is my code : 什么都不显示,这是我的代码:

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");
            }
        },
    });
}​

Here is my code in the controller: 这是我在控制器中的代码:

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";
    }

}

I noticed that it is $response = $this->gcal->eventInsert($params); 我注意到这是$response = $this->gcal->eventInsert($params); which causes the error(I registered the app on google api console) 导致错误(我在Google API控制台上注册了该应用)

Could anyone help me please? 有人可以帮我吗?

Add a fail with it... 添加失败...

For example: 例如:

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

I am pretty sure, it is failing. 我很确定,它正在失败。 Also check your Console for extra information. 另请检查您的控制台以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM