我在 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);
导致错误的原因(我在 google api 控制台上注册了该应用程序)
有人可以帮我吗?