doubushi0031 2013-11-21 12:42
浏览 45

将请求的ID发送给PHP

JS FILE

buttons: {
               save : function() {
                  calEvent.id = id;
                  id++;
                  calEvent.start = new Date(startField.val());
                  calEvent.end = new Date(endField.val());
                  calEvent.title = titleField.val();
                  calEvent.body = bodyField.val();

                  //post to events.php
                  $.post("events.php?action=save&start="+calEvent.start.getTime()/1000+"&end="+calEvent.end.getTime()/1000+"&title="+calEvent.title+"&body="+calEvent.body);

                  $calendar.weekCalendar("removeUnsavedEvents");
                  $calendar.weekCalendar("updateEvent", calEvent);
                  $dialogContent.dialog("close");
               },,
            "delete"  : function() {
                  calEvent.id = id;
                  id++;

                  //post to events.php
                 $.post( "events.php", { action: "del", id: calEvent.id });

                  $calendar.weekCalendar("removeEvent", calEvent.id);
                  $dialogContent.dialog("close");


                } ,
               cancel : function() {
                  $dialogContent.dialog("close");
               }
            }
         }).show();

PHP FILE

if ($action == 'del')
{
    $id = $_GET['id']; 

    $del = "DELETE FROM meeting_rooms_calendar WHERE id='$id'";
    $result = mysql_query($del, $link);
    print_r($id);
} 
elseif($action == 'save')
{
    $title = $_REQUEST['title'];
    $body = $_REQUEST['body'];
    $start_time = (int)$_REQUEST['start'];
    $start_time = $start_time + 60*60;
    $end_time = (int)$_REQUEST['end'];
    $end_time = $end_time + 60*60;
    $start = date('c',$start_time);
    $end = date('c',$end_time);
    $sql = "INSERT INTO meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
    $result = mysql_query($sql, $link);

}

Now if I click save, save will post the request variables to PHP and PHP to the database, when I click DELETE it doesn't send the requested ID to PHP so PHP can't delete it from database how can I make the JS file send the ID to PHP.

If I do it manually by

www.myweb.com/events.php?action=del&id=1

This will delete it from database, so that means PHP works. It's just the JS part, it don't delete it automatically from database.

  • 写回答

2条回答 默认 最新

  • douchuose2514 2013-11-21 12:46
    关注

    You need use $_POST instead of $id = $_GET['id']; since you are using jquery $.post method

    $action = $_POST['action'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行