Php 在codeigniter中使用ajax插入和检索数组数据

Php 在codeigniter中使用ajax插入和检索数组数据,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我试图在Codeigniter中使用ajax插入和检索数组数据,我尝试了下面的代码,代码不起作用,任何人都可以告诉我解决方案 $('#click').click(function(){ var selected = new Array(); $(".stafftable input[type=checkbox]:checked").each(function(){ selected.push(this.value);

我试图在Codeigniter中使用ajax插入和检索数组数据,我尝试了下面的代码,代码不起作用,任何人都可以告诉我解决方案

$('#click').click(function(){
          var selected = new Array();
          $(".stafftable input[type=checkbox]:checked").each(function(){
          selected.push(this.value);
          });
          var selected_member_id=localStorage.getItem('selectids');
          var myarray=selected_member_id.split(','); // convert string to an array
          $.ajax({
            type: "POST",
            url:"<?php echo base_url();?>Welcome/send_to_staff", 
            data: {staff_id:selected,members_id:myarray},

                  success: 
                  function(data)
                      {
                         if(data==true){
                            // localStorage.clear();
                            load_unseen_notification();
                          }
                          else{
                            alert("localstorage not cleared");
                          }

                      }
            });
    });

您必须在代码中进行这样的更改。希望它能起作用

$('#click').click(function(){
            var selected = new Array(); //assigning array to variable

        $(".stafftable input[type=checkbox]:checked").each(function(){
          selected.push(this.value);
          });
       var selected_member_id=localStorage.getItem('selectids');
          var string_selected=selected.toString(); //converting array to string

            $.ajax({
                type: "POST",
                url:"<?php echo base_url();?>Welcome/send_to_staff", 
                data: {staff_id:string_selected,members_id:selected_member_id}, //string selected

                      success: 
                      function(data)
                          {

                             if(data==true){
                                // localStorage.clear();
                                load_unseen_notification();
                              }
                              else{
                                alert("localstorage not cleared");
                              }

                          }
                });

        });

您必须在代码中进行这样的更改。希望它能起作用

$('#click').click(function(){
            var selected = new Array(); //assigning array to variable

        $(".stafftable input[type=checkbox]:checked").each(function(){
          selected.push(this.value);
          });
       var selected_member_id=localStorage.getItem('selectids');
          var string_selected=selected.toString(); //converting array to string

            $.ajax({
                type: "POST",
                url:"<?php echo base_url();?>Welcome/send_to_staff", 
                data: {staff_id:string_selected,members_id:selected_member_id}, //string selected

                      success: 
                      function(data)
                          {

                             if(data==true){
                                // localStorage.clear();
                                load_unseen_notification();
                              }
                              else{
                                alert("localstorage not cleared");
                              }

                          }
                });

        });

什么是
$staff\u id
$members\u id
?ajax调用中的url``url:“Welcome/send\u to\u staff”``不应该包含大写字母W它应该是`url:`````,尝试检查$staff\u id和$members\u id新变量,并将发布的数据分配给这些变量您得到了什么错误?您试过调试它吗?您也检查过Netwrok选项卡中的ajax请求了吗?它会将所有数据发送到服务器吗?
$staff\u id
$members\u id
?ajax调用中的url``url:“Welcome/send\u to\u staff”``不应该包含大写字母,应该是`url:````,请尝试检查$staff_id和$members_id新变量和发布的数据是否分配给这些变量您会遇到什么错误?你们试过调试它吗?你们也检查过Netwrok选项卡中的ajax请求了吗?它是否将所有数据发送到服务器?
public function send_to_staff(){

    $staff_id=$this->input->post('staff_id');
    $staff_id=json_encode($staff_id); //converting to json
    $membersids[]= $this->input->post('members_id');
    $members_id=json_encode($membersids);  //converting to json

    if($staff_id !==''){  
        $data['staff_id']=$staff_id;
        $data['members_id']=$members_id;
         $inserted=$this->db->insert('ag_matched_members',$data); //insert query
        if($inserted == true){
            echo true; //returns true
        }
        else
        {
            echo false;  //returns false
        }

    }

}