doukongpao0903 2013-05-17 14:19
浏览 51

FullCalendar和Symfony 1.3在没有表单的情况下在数据库中插入数据

i'm trying to use fullCalendar's plugin in my symfony projet, but i have some trouble to insert data into database. i have a page calendar/index, where we can see the calendar, and the javascript to create an event etc.

my first approach was to do something simple. Insert the title of the event in database, for that i try this :

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

And now i would like to insert the title in my database with the executeData in actions.class.php, but the only way to insert data into database that i know is with form. My question is : Can i do something like that, and if yes, how insert data in the database ?

  • 写回答

1条回答 默认 最新

  • dongying195959 2013-05-17 17:12
    关注

    You have to grab in php the header sent to your php script:

    First change this and try:

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

    In the beggining of your php script you should have this:

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

    Also make sure your in the same domain, cross domain ajax requests are a pain...

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示