发布ajax curl php时的NULL值

时间:2018-05-05 09:46:06

标签: php ajax codeigniter curl php-curl

为什么在codeigniter中始终使用CURL方法从Ajax中获取NULL值数据?

这是我的错误:

  

发生数据库错误错误号:23000/515 [Microsoft] [ODBC   用于SQL Server的驱动程序11] [SQL Server]无法将值NULL插入   列'noreg',表'DBRS_MARGONO.dbo.VKLAIM_VERIF';专栏没有   允许空值。 INSERT失败。插入“VKLAIM_VERIF”(“noreg”,   “user_id”,“Verified”,“level_verif”,“catatan”)VALUES(NULL,NULL,   NULL,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-urlencoded

在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元素。

1 个答案:

答案 0 :(得分:0)

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

相关问题