【问题标题】:Update function dialog jquery php更新函数对话框 jquery php
【发布时间】:2014-03-04 14:28:32
【问题描述】:

我正在使用全日历。当我点击一个事件时,它会打开一个对话框,我可以在其中看到当前事件的标题/描述/开始日期/结束日期。我有一个更新编辑按钮,所以当我更改其中一个变量时,它会更改数据库中的变量。但这不起作用。

agenda_view.php:

<html>
<head>
<link href='<?=base_url();?>testcalendar/css/fullcalendar.css' rel='stylesheet' />
<script src='<?=base_url();?>testcalendar/js/jquery-1.9.1.min.js'></script>
<script src='<?=base_url();?>testcalendar/js/jquery-ui-1.10.2.custom.min.js'></script>
<script src='<?=base_url();?>testcalendar/js/fullcalendar.min.js'></script>
<script src='<?=base_url();?>testcalendar/js/fullcalendarextern.js'></script>
<script src='<?=base_url();?>testcalendar/js/nieuweafspraak.js'></script>
<link href="<?=base_url();?>testcalendar/assets/css/jquery-ui-1.10.0.custom.css" rel="stylesheet" type="text/css" />

<style>

 body {
  margin-top: 40px;

  }


 #calendar {
  width: 900px;
  margin: 0 auto;
  }

</style>
</head>
<body>
<div id="dialogstatusevent" style="display:none" title="Mijn Afspraak">
<form>
    <div class="control-group">
                <div class="controls">      
        <label class="control-label">Titel:</label>
        <input type="text" name="title" id="titlestatus" class="text ui-widget-content ui-corner-all">
                </div>
    </div>
    <div class="control-group">
                <div class="controls">  
        <label class="control-label">Description:</label>
        <input type="text" name="description" id="descstatus" class="text ui-widget-content ui-corner-all">
                </div>
    </div>
    <div class="control-group">
                <div class="controls">  
        <label class="control-label">Van:</label>
        <input type="text" name="datestatusstart" id="datestatusstart" class="text ui-widget-content ui-corner-all">
                </div>
    </div>
    <div class="control-group">
                <div class="controls">  
        <label class="control-label">Tot:</label>
        <input type="text" name="datestatusend" id="datestatusend" class="text ui-widget-content ui-corner-all">
                </div>
    </div>
        </form>
</div>
<div id='calendar'></div>
</body>
</html>

Fullcalendarextern.js:

$(document).ready(function() {
  var date = new Date();
  var d = date.getDate();
  var m = date.getMonth();
  var y = date.getFullYear();

  var calendar = $('#calendar').fullCalendar({
   editable: true,
   header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
   },

   events: "../testcalendar/fullcalendar/events.php",



   // Convert the allDay from string to boolean
   eventRender: function(event, element, view) {
    if (event.allDay === 'true') {
     event.allDay = true;
    } else {
     event.allDay = false;
    }
   },   
   selectable: true,
   selectHelper: true,
   select: function(start, end, allDay) {
   var title = prompt('Event Title:');
   if (title) {
   var start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
   var end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
   $.ajax({
   url: '../testcalendar/fullcalendar/add_events.php',
   data: 'title='+ title+'&start='+ start +'&end='+ end ,
   type: "POST",

   });
   calendar.fullCalendar('renderEvent',
   {
   title: title,
   start: start,
   end: end,
   allDay: allDay
   },
   true // make the event "stick"
   );
   }
   calendar.fullCalendar('unselect');
   },
    editable: true,
   eventDrop: function(event, delta) {
   var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
   var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
   $.ajax({
   url: '../testcalendar/fullcalendar/update_events.php',
   data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
   type: "POST",

   });
   },
   eventResize: function(event) {
   var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
   var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
   $.ajax({
    url: '../testcalendar/fullcalendar/update_events.php',
    data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
    type: "POST",

   });

},


eventClick: function(calEvent, jsEvent, view) {
$( "#dialogstatusevent" ).dialog({
    autoOpen: false,
    height: 'auto',
    width: 'auto',
    modal: true,
    closeOnEscape:true, 
    resizable:false, 
    show:'fade',
    buttons: { 
      "Edit": function() {
      var titlestatus = $("#titlestatus").val(),
        descstatus = $('#descstatus').val(),
        datestart = $('#datestatusstart').val(),
        dateend = $('#datestatusend').val();


     $.post('../testcalendar/db/processupdate.php',{
            user_name: titlestatus, user_desc: descstatus, user_start: datestart, user_end: dateend, action:'joined'
        }); var nTime = 1 * 50;
                window.setTimeout("location.reload()", nTime);//End Post
        $("#titlestatus").val('');
        $("#descstatus").val('');
        $("#datestatusstart").val('');
        $("#datestatusend").val('');    
        $(this).dialog("close");

        },
        "Cancel": function() { 
        $("#titlestatus").val('');
        $("#descstatus").val('');
        $("#datestatusstart").val('');
        $("#datestatusend").val('');
        $(this).dialog("close"); 
        } 

    }
    }

    );

    $("#titlestatus").val(calEvent.title),
    $("#descstatus").val(calEvent.description),
    $("#datestatusstart").val(calEvent.end),
    $("#datestatusend").val(calEvent.start),
    $("#datestatusstart").datepicker({ dateFormat: 'yy-mm-dd' }),
    $("#datestatusend").datepicker({ dateFormat: 'yy-mm-dd' });

    $( "#dialogstatusevent" ).dialog( "open" );

    },

   eventMouseover: function(event, domEvent) {
                var layer = '<div id="events-layer" class="fc-transparent" style="position:absolute; width:100%; height:100%; top:-1px; text-align:right; z-index:100"><a><img src="../testcalendar/editbt.png" title="edit" width="14" id="edbut'+event.id+'" border="0" style="padding-right:3px; padding-top:2px;" /></a><a><img src="../testcalendar/delete.png" title="delete" width="14" id="delbut'+event.id+'" border="0" style="padding-right:5px; padding-top:2px;" /></a></div>';
                $(this).append(layer);
                $("#delbut"+event.id).hide();
                $("#delbut"+event.id).fadeIn(300);
                $("#delbut"+event.id).click(function() {
                $.ajax({
                url: '../testcalendar/fullcalendar/delete_events.php',
                data: 'id=' + event.id ,
                type: "POST",
                });
                var nTime = 1 * 50;
                window.setTimeout("location.reload()", nTime);
                });
                $("#edbut"+event.id).hide();
                $("#edbut"+event.id).fadeIn(300);
                $("#edbut"+event.id).click(function() {
                    var title = prompt( '\n\nNew Event Title: ');

                    if(title){
                $.ajax({
                url: '../testcalendar/fullcalendar/update_title.php',
                data: 'title='+ title+'&id='+ event.id ,
                type: "POST",
                });
                var nTime = 1 * 50;
                window.setTimeout("location.reload()", nTime);
                    }


                });
            },   

            eventMouseout: function(calEvent, domEvent) {
                $("#events-layer").remove();
            },


  });

 });

进程更新.php:

<?php
//include db configuration file
include 'connection.php';
function user_joined($user_name,$user_desc, $user_start, $user_end){
        $q = "UPDATE evenement SET title='". $user_name ."'description='". $user_desc ."'start='". $user_start ."'end='". $user_end ."' WHERE id=".$id;
    mysql_query($q);
    }

{
        $user_name=$_POST['user_name'];
        $user_desc=$_POST['user_desc'];
        $user_start=$_POST['user_start'];
        $user_end=$_POST['user_end'];
        $action=$_POST['action'];
        if ($action=='joined'){
            user_joined($user_name, $user_desc, $user_start, $user_end);
            }
    }
/*if ( (isset($_POST["id"]) && strlen($_POST["id"]) >= 3 && strlen($_POST["id"]) <= 60) &&
    (isset($_POST["name"]) && strlen($_POST["name"]) >= 3 && strlen($_POST["name"]) <= 50) &&
    (isset($_POST["age"]) && strlen($_POST["age"]) >= 3 && strlen($_POST["age"]) <= 40) ) 
{   //check $_POST["name"] and $_POST["address"] and $_POST["city"] are not empty

    $id   = $_POST["id"];
    $name = $_POST["name"];
    $age   = $_POST["age"];

    $q = "INSERT INTO tbltest ( id, name, age) VALUES 
            ('".$id."','".$name."','".$age."')";
    mysql_query($q); 

}*/

?>

connection.php:

<?php
    $db_host = "localhost"; 
    // Place the username for the MySQL database here 
    $db_username = "roots";  
    // Place the password for the MySQL database here 
    $db_pass = "root";  
    // Place the name for the MySQL database here 
    $db_name = "blackboks-calendar"; 

    // Run the actual connection here  
    mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
    mysql_select_db("$db_name") or die ("no database");              
?>

【问题讨论】:

  • 你的控制台出现什么错误?
  • 我没有收到任何错误:(
  • 检查你得到什么回应? $.post('../testcalendar/db/processupdate.php',{ user_name: titlestatus, user_desc: descstatus, user_start: datestart, user_end: dateend, action:'joined'},function(response){ alert(response); });
  • 我得到一个对话框,但里面什么都没有:O
  • 您的控制器看起来与 processupdate.php 中不必要的 } 有问题

标签: javascript php jquery dialog fullcalendar


【解决方案1】:

如果您收到警报,请尝试?

<?php

include 'connection.php';

function user_joined($user_name,$user_desc, $user_start, $user_end)
{
   $q = "UPDATE evenement SET title='". $user_name ."'description='". $user_desc ."'start='". $user_start ."'end='". $user_end ."' WHERE id=".$id;
    mysql_query($q);
}

    $user_name=$_POST['user_name'];
    $user_desc=$_POST['user_desc'];
    $user_start=$_POST['user_start'];
    $user_end=$_POST['user_end'];

    $action=$_POST['action'];

    if ($action=='joined')
    user_joined($user_name, $user_desc, $user_start, $user_end);

   print_r($_POST);             
  ?>

id 也通过POST 传递,您需要发送所需的id

 $.post('../testcalendar/db/processupdate.php',
{  'user_name' : titlestatus,         'user_desc': descstatus, 'user_start' : datestart, 'user_end' : dateend, 'action':'joined' ,'id' : id },
 function(response){ 
    alert(response);        
 });

【讨论】:

  • 是的,我收到带有回声“是”的警报
  • 是的,我想是的,但是当我查看数据库时,它没有更新:(我在对话框中的 fullcalendarextern.js 中做错了什么吗?或类似的东西?
  • 检查您是否获得有效的POST 值,检查更新的答案?
【解决方案2】:

它不回显 id。

进程更新.php:

<?php

include 'connection.php';

function user_joined($user_name,$user_desc, $user_start, $user_end)
{
   $q = "UPDATE evenement SET title='". $user_name ."'description='". $user_desc ."'start='". $user_start ."'end='". $user_end ."' WHERE id=".$id;
    mysql_query($q);
}
    $id=$_POST['id'];
    $user_name=$_POST['title'];
    $user_desc=$_POST['user_desc'];
    $user_start=$_POST['user_start'];
    $user_end=$_POST['user_end'];

    $action=$_POST['action'];

    if ($action=='joined')
    user_joined($user_name, $user_desc, $user_start, $user_end);
    echo $id;
   print_r($_POST);  ?>

【讨论】:

  • 我做到了;) 这很有帮助:) 但我不明白它不会更新 :( 在我的数据库中。
  • 你是从前端发送id吗?
  • 我找到了答案,它只是在 description= start= 和 end= 之前的一些逗号。感谢您的帮助!
  • 干杯,请接受我的回答或更新它,然后接受谢谢!
【解决方案3】:

像这样?它也不会在警报中输出任何内容:(

<?php
include 'connection.php';
function user_joined($user_name,$user_desc, $user_start, $user_end){
        $q = "UPDATE evenement SET title='". $user_name ."'description='". $user_desc ."'start='". $user_start ."'end='". $user_end ."' WHERE id=".$id;
    mysql_query($q);
    }

{
        $user_name=$_POST['user_name'];
        $user_desc=$_POST['user_desc'];
        $user_start=$_POST['user_start'];
        $user_end=$_POST['user_end'];
        $action=$_POST['action'];
        if ($action=='joined')
            user_joined($user_name, $user_desc, $user_start, $user_end);

    } ?>

【讨论】:

  • 当然你可以:) 我已经用声明的 id 实现了你的编辑版本,但它也没有输出任何东西:(。但你很有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多