dszdiavv474681 2018-05-05 09:46 采纳率: 0%
浏览 53

发布ajax curl php时的NULL值

Why always NULL value data from Ajax with CURL method in codeigniter?

Here is my error:

A Database Error Occurred Error Number: 23000/515 [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot insert the value NULL into column 'noreg', table 'DBRS_MARGONO.dbo.VKLAIM_VERIF'; column does not allow nulls. INSERT fails. INSERT INTO "VKLAIM_VERIF" ("noreg", "user_id", "verified", "level_verif", "catatan") VALUES (NULL, NULL, NULL, 0, '') Filename: C:/xampp/htdocs/ws/system/database/DB_driver.php Line Number: 691

and here are my controller to print when ajax is called:

$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;

But when I test my post data $post is sent and I think the problem in CURL POST method. I have been searching solutions and I don't know where is the error. Web service works well when I test it in Postman with POST method x-www-form-urlencoded

Here are my ajax code:

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

I send return data value from web service to #btnverif element.

  • 写回答

1条回答 默认 最新

  • duanlu1793 2018-05-05 11:22
    关注

    after help from @Arthur I add json_encode to curl_setopt($ch, CURLOPT_POSTFIELDS, $post); thanks you #SOLVED

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器