FullCalendar,Symfony 1.3在数据库中插入数据不需要表单


FullCalendar & Symfony 1.3 insert data in DB without form

我试图在我的symfony项目中使用fullCalendar的插件,但我有一些麻烦将数据插入数据库。我有一个页面日历/索引,在那里我们可以看到日历,和javascript创建一个事件等。

我的第一个方法是做一些简单的事情。在数据库中插入事件的标题,为此我尝试这样做:

$.ajax({
    type: "POST",
    url: "calendar/data",
    data: title,
    dataType: 'script'
});

现在我想在我的数据库中插入标题与executeData在actions.class.php,但唯一的方法来插入数据到数据库中,我知道是与形式。我的问题是:我可以这样做吗?如果是,如何在数据库中插入数据?

你必须在php中抓取发送到php脚本的header:

首先改变这个,并尝试:

$.ajax({
    type: "POST",
    url: "calendar/data",
    data: {title:'my title to insert'}, //data: title,
    //dataType: 'script' remove this
});

在php脚本的开头,你应该这样写:

<?php
//Error Reporting -> You don´t need to have the next 4 lines, ignore them.
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);

/*Try to fetch the title*/
if($_POST['title']){ 
   var_dump($_POST['title']);
   //You should see your title on top of the webpage or in network debug from chrome or firefox in XHR separator
 }else{ echo "Crap no title"; } 
 ?>

还要确保您在同一域中,跨域ajax请求是一个痛苦的…