douqi1625 2017-03-03 07:47
浏览 48

$ _GET无法遍历数组

I have dataId from checkbox values and I'm sending it using a GET AJAX request:

dataId = 1, 2, 16, 15, 17, 3, 14, 5, 9, 11;
URI = "<?php echo site_url('Terpasang/Update_Kebutuhan_ke_Terpasang')?>";
$.ajax({
    url : URI,
    type: "GET",
    data: { "iddata": [dataId] },
    dataType: "JSON",
});

In controller I am passing this data with code:

$iddata = array($_GET['iddata']);
$Countdata = count($iddata);
for($i = 0; $i <= $Countdata; $i++)
{
    $data = array('id_perjal'=>$iddata[$i]); // this code can't generate id one by one like i wanna : 1, next 2, next 16 etc 
    $this->M_perjal_terpasang->save($data);
}
echo json_encode(array("status" => TRUE));
  • 写回答

4条回答 默认 最新

  • dpgui8229808 2017-03-03 07:55
    关注

    The issue is with how you build the array. You cannot set a variable equal to a comma list of values. If you check the code you'll see that dataId only has a single value:

    dataId = 1, 2, 16, 15, 17, 3, 14, 5, 9, 11;
    data = {
        "iddata": [dataId]
    };
    
    console.log(data);

    To fix this define the dataId as an array explicitly:

    var dataId = [1, 2, 16, 15, 17, 3, 14, 5, 9, 11]; // note the [] wrapping the values
    

    Then use it in the object you provide to data:

    data: { "iddata": dataId },
    
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题