php - 使用ajax处理将日期插入数据库时日期更改(CodeIgniter)
问题描述
我正在使用 CodeIgniter 框架并使用 jQuery 和 ajax 从输入中插入数据。问题是当我在 ajax 中处理它时日期会发生变化。我使用 MySQL 作为数据库,数据类型是日期。
我试图更改日期的格式,因为它可能不是相同的格式。
jQuery/Ajax:
$(document).on('submit', '#insertQL_form', function(event){
event.preventDefault();
var month = $('#datetimepicker1').val();
var nameCompany = $('#nameCompany').val();
var email = $('#email').val();
var position = $('#position').val();
var ojLink = $('#ojLink').val();
var remarks = $('#remarks').val();
var withTestTask = $('#withTestTask').val();
var testTaskStatus = $('#testTaskStatus').val();
var withInterview = $('#withInterview').val();
var overallStatus = $('#overallStatus').val();
alert(month);
$.ajax({
url:"<?php echo base_url() . 'home/insertQL'?>",
method:'POST',
data: new FormData(this),
contentType:false,
processData:false,
success:function(data)
{
alert(data);
}
});
});
控制器功能:
public function insertQL()
{
if($_POST["action"] == "Add")
{
$insert_data = array(
'month' => date("Y-m-d",$this->input->post('month')),
'nameCompany' => $this->input->post('nameCompany'),
'email' => $this->input->post('email'),
'position' => $this->input->post('position'),
'ojLink' => $this->input->post('ojLink'),
'remarks' => $this->input->post('remarks'),
'withTestTask' => $this->input->post('withTestTask'),
'testTaskStatus' => $this->input->post('testTaskStatus'),
'withInterview' => $this->input->post('withInterview'),
'overallStatus' => $this->input->post('overallStatus')
);
$this->load->model('QLModel');
$this->QLModel->insert_crud($insert_data);
echo 'Data Inserted';
}
}
解决方案
您应该在插入数据库之前尝试此操作。
$m = strtr($this->input->post('month'), '/', '-');
然后像这样插入它。
'month' => date('Y-m-d', strtotime($m)),
让我知道结果。
推荐阅读
- dart - 如何根据标志为 FloatingActionButton 提供两种不同的操作
- selenium - 如何从 selenium webdriver 中的 span 中选择下拉选项
- reporting-services - SSRS - 在参数中发送多个 ID 值并为参数中的每个值生成 tablix 行
- typescript - 是否可以将 JSDoc 记录为 VSCode 的动态函数?
- azure - 如何为应用服务配置 Azure 自定义域
- matlab - 如何调用位于 Function Caller 模块上方 2 层的 Simulink 函数?
- javascript - 我需要将博客文章分块发送给谷歌进行翻译,因为我不断收到太多请求的 429 错误
- c++ - 将参数传递给 IMPLEMENT_DYNCREATE
- qt - 像 ListModel 这样的 QObject 集合
- javascript - 使用 jQuery Validate 插件在多个部分中验证表单