【问题标题】:Update date field in a row after datepicker change更改日期选择器后连续更新日期字段
【发布时间】:2023-04-08 02:18:01
【问题描述】:

我有一个表格,其中包含一列可以通过日期选择器更改的日期。

<td>
   <div class="input-group date" data-provide="datepicker">
        <input type="text" class="form-control" name="dataPrevisao" id="dataPrevisao" rel="<?php echo odbc_result($resultado,"stamp");?>" value="<?php echo odbc_result($resultado,"dvalor");?>" />
        <div class="input-group-addon">
             <span class="glyphicon glyphicon-calendar small"></span>
        </div>
   </div>

我想要做的是,在日期更改后,表中的寄存器会自动更新。 为此,我有一个 php 文件 - changePrevisao.php:

<?php include("includes/odbc.ini"); 
$iniciais=str_replace(' ', '', $_SESSION['iniciais']);
$stamp=$_POST['stamp']; 
$dataP=$_POST['dataP']; 
$query = "  update od set marcada=1, data='$dataP', usrdata=convert(varchar(10),getdate(),112),
            usrhora=right(convert(varchar(19),getdate(),121),8), usrinis='$iniciais' where od.odstamp='$stamp'";
odbc_exec($sqlconnect,$query); 
?>

我在构建允许将数据传递到 php 文件的 ajax 用户函数时遇到问题,有人可以帮助我吗?

【问题讨论】:

标签: php jquery datepicker


【解决方案1】:

经过搜索和测试,我创建了以下函数:

<script>
    $(document).ready(function(){
    $(document).on('change', '#dataPrevisao', function () {
        var stamp = $(this).attr('rel');
        var dataP = $(this).val();
        var dataString = 'stamp='+ stamp +'&dataP='+ dataP;
        $.ajax({
            type: "POST",
            url: "changePrevisao.php",
            data: dataString,
            cache: false,
            success: function(new_data){
                    $(stamp).html(new_data);
                    $(stamp).dialog();
                    alert('Load was performed.');
    }
   });
  });
});
</script>

现在我可以更新数据库中的日期,但结果与我预期的不一样,只有当我直接更改输入而不是通过日期选择器更改时才会发生更改。我需要在函数中进行哪些更改,以便它考虑到 datepicker 所做的更改?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    相关资源
    最近更新 更多