发布 ajax curl php 时的 NULL 值



为什么在codeigniter中使用CURL方法总是从Ajax中为空值数据?

这是我的错误:

发生数据库错误错误号:23000/515 [Microsoft][ODBC SQL Server 的驱动程序 11][SQL Server]无法将值 NULL 插入到 列 'noreg', table 'DBRS_MARGONO.dbo.VKLAIM_VERIF';列不 允许空值。插入失败。插入"VKLAIM_VERIF"("诺雷格", "user_id"、"已验证"、"level_verif"、"卡塔坦") 值(空、空、 空, 0, '') 文件名: C:/xampp/htdocs/ws/system/database/DB_driver.php 行号:691

以下是调用 Ajax 时要打印的控制器:

$post = array();
$post['noreg'] = $this->input->post('noreg');
$post['user'] = $this->input->post('user');
$post['status'] = $this->input->post('verified');
$url = 'http://localhost/ws/rsms/verifupdatesimpanstatus';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json; charset=utf-8",
"X-API-Key: " . $aksesws['X-API-Key'],
"IDAPP: " . $aksesws['IDAPP'])
);
$de = curl_exec($ch);
$d = json_decode($de, true);
curl_close($ch);
echo $de;

但是当我测试我的帖子数据时,$post被发送,我认为 CURL POST 方法存在问题。我一直在寻找解决方案,但我不知道错误在哪里。当我使用POST方法x-www-form-urlencoding在 Postman 中测试它时,Web 服务运行良好

这是我的 ajax 代码:

function updateStatusVerif(noreg,user,verified) {
$.post("<?php echo base_url();?>superuser/pasien/updateStatusVerif",
{
noreg : noreg,
user : user,
verified : verified
},
function(data){
$('#btnverif').html(data);
});
}

我将返回数据值从 Web 服务发送到 #btnverif 元素。

在@Arthur的帮助下,我curl_setopt($ch, CURLOPT_POSTFIELDS, $post);添加了json_encode,谢谢 #SOLVED

最新更新