Как объединить и выбрать вызовы JSON?

Как правило, если запрос DELETE отправляет данные в тело запроса, вы можете прочитать данные с помощью следующего кода:

$data = file_get_contents("php://input");

В зависимости от кодировки данных (обычно JSON или форма- закодировано), вы используете json_decode или parse_str для чтения данных в пригодные для использования переменные.

Для простого примера см. в этой статье , где автор использует форматированные данных для обработки запроса PUT. DELETE работает аналогично.


В вашем случае, однако, похоже, что имя файла считывается с URL-адреса запроса (вызов $this->uri->segment(3);). Когда я смотрю на ваш код, кажется, что переменная $gll_id не инициализирована, и вы не проверяете, являются ли результирующий объект $w и переменная $gll_name пустыми. Возможно, это приводит к сбою удаления. Включите ведение журнала ошибок с помощью ini_set("log_errors",1); и просмотрите журнал ошибок сервера. Если сбой связи отключен, журнал ошибок должен содержать путь, который PHP пытался отключить - вероятно, что путь неправильный.

1
задан Natasha 18 March 2019 в 00:10
поделиться

3 ответа

так что это полное решение, к сожалению, я утратил привычку кодировать jQuery, поэтому это решение ES6 (которое я считаю действительно менее сложным)

var
  first = [
    { "id": 1,  "text": "MEN", "children": [
      { "id": 10, "text": "back" },
      { "id": 11, "text": "accesoris", "children": [
        { "id": 110, "text": "back" },
        { "id": 111, "text": "hat"  },
        { "id": 112, "text": "belt" }
      ]},
      { "id": 12, "text": "cloting", "children": [
        { "id": 120, "text": "back"   },
        { "id": 121, "text": "blazer" },
        { "id": 122, "text": "pants"  }
      ]},
      { "id": 13, "text": "shoes", "children": [
        { "id": 130, "text": "back"   },
        { "id": 131, "text": "oxford" },
        { "id": 132, "text": "chukka" }
      ]}
    ]},
    { "id": 2, "text": "WOMEN", "children": [
      { "id": 20, "text": "back" },
      { "id": 21, "text": "accesoris", "children": [
        { "id": 210, "text": "back"  },
        { "id": 211, "text": "ring"  },
        { "id": 212, "text": "glove" }
      ]},
      { "id": 22, "text": "cloting", "children": [
        { "id": 220, "text": "back"   },
        { "id": 221, "text": "tshirt" },
        { "id": 222, "text": "dress"  }
      ]},
      { "id": 23, "text": "shoes", "children": [
        { "id": 230, "text": "back"    },
        { "id": 231, "text": "sandals" },
        { "id": 232, "text": "heels"   }
      ]}
    ]},
    { "id": 3, "text": "KIDS" }
  ]
  ,
  second = [
    { "id": 1, "text": "Customer Care", "children": [
      { "id": 10, "text": "back" },
      { "id": 11, "text": "Product Information" },
      { "id": 12, "text": "Payment Information" },
      { "id": 13, "text": "Your Order" }
    ]},
    { "id": 2, "text": "Contact", "children": [
      { "id": 20, "text": "back"    },
      { "id": 21, "text": "Careers" },
      { "id": 22, "text": "Affiliates" }
    ]}
  ];
;

const
  fullList = first.concat(second)
  ,
  myList   = document.querySelector('#my-List')
  ,
  Messager = { 
    _zone : document.getElementById('MsgZone'),
    Text(msg) {
      this._zone.textContent = msg;
      setTimeout(that=>that._zone.textContent='', 900, this);
    }
  };

var
  List_Level   = [],
  current_List = fullList,
  LI_elm       = document.createElement('li');


function ShowList_F()
{
  let
    xList = fullList,
    showingTxt = '';

  List_Level.forEach( x=>{
    showingTxt += ` / ${xList[x].text}`
    xList=xList[x].children
  })

  while( myList.firstChild )
    { myList.removeChild( myList.firstChild ); }

  current_List = xList;

  xList.forEach((e,i)=>{
    let xLI = myList.appendChild(LI_elm.cloneNode(false));
    xLI.dataset.ref = i.toString();
    xLI.textContent = e.text;

    if (e.text==='back') { xLI.className='back' }
  })

  Messager.Text(showingTxt)
}


ShowList_F(); // first attempt


myList.onclick = function(e)
{
  if (!e.target.matches('li')) return;
  e.stopPropagation();

  let xItem = parseInt(e.target.dataset.ref);

  if (e.target.textContent==='back')
  {
    List_Level.pop()
    ShowList_F();
  }
  else if ( 'children' in current_List[ xItem ])
  {
    List_Level.push(xItem);
    ShowList_F();
  }
  else
  {
    Messager.Text('nothing to do with this click')
  }
}
#my-List { cursor: pointer; list-style-type:square }
#MsgZone, .back { font-size: 0.8em; font-style: italic }
[ 112]

0
ответ дан MrJ 18 March 2019 в 00:10
поделиться

Если вы хотите объединить два массива вместе, вы можете просто использовать concat.

var fullList = first.concat(second);

0
ответ дан Kent Widman 18 March 2019 в 00:10
поделиться

Хорошо, это версия jQuery

var
  first = [
    { "id": 1,  "text": "MEN", "children": [
      { "id": 10, "text": "back" },
      { "id": 11, "text": "accesoris", "children": [
        { "id": 110, "text": "back" },
        { "id": 111, "text": "hat"  },
        { "id": 112, "text": "belt" }
      ]},
      { "id": 12, "text": "cloting", "children": [
        { "id": 120, "text": "back"   },
        { "id": 121, "text": "blazer" },
        { "id": 122, "text": "pants"  }
      ]},
      { "id": 13, "text": "shoes", "children": [
        { "id": 130, "text": "back"   },
        { "id": 131, "text": "oxford" },
        { "id": 132, "text": "chukka" }
      ]}
    ]},
    { "id": 2, "text": "WOMEN", "children": [
      { "id": 20, "text": "back" },
      { "id": 21, "text": "accesoris", "children": [
        { "id": 210, "text": "back"  },
        { "id": 211, "text": "ring"  },
        { "id": 212, "text": "glove" }
      ]},
      { "id": 22, "text": "cloting", "children": [
        { "id": 220, "text": "back"   },
        { "id": 221, "text": "tshirt" },
        { "id": 222, "text": "dress"  }
      ]},
      { "id": 23, "text": "shoes", "children": [
        { "id": 230, "text": "back"    },
        { "id": 231, "text": "sandals" },
        { "id": 232, "text": "heels"   }
      ]}
    ]},
    { "id": 3, "text": "KIDS" }
  ]
  ,
  second = [
    { "id": 1, "text": "Customer Care", "children": [
      { "id": 10, "text": "back" },
      { "id": 11, "text": "Product Information" },
      { "id": 12, "text": "Payment Information" },
      { "id": 13, "text": "Your Order" }
    ]},
    { "id": 2, "text": "Contact", "children": [
      { "id": 20, "text": "back"    },
      { "id": 21, "text": "Careers" },
      { "id": 22, "text": "Affiliates" }
    ]}
  ];
;

const
  fullList = first.concat(second) ,
  $myList  = $('#my-List') ;

var
  List_Level   = []       ,
  current_List = fullList ;

function ShowList_F()
{
  let xList = fullList;

  for (let x=0, xMax=List_Level.length; x<xMax; x++)
  {
    xList = xList[ List_Level[x] ].children;
  }

  $myList.empty()

  current_List = xList;

  for (let i=0, iMax=xList.length; i<iMax; i++)
  {
    let aClass = 'levelentry' + (xList[i].hasOwnProperty('children')?' PLUS':'');   // other possibility

    $myList.append( `<li class="root-level"><a class="${aClass}" data-ref="${i}">${xList[i].text}</a></li>`);
  }
}

ShowList_F(); // first attempt


$myList.on( "click", "a", function(e)
{
  e.preventDefault();
  
  let xItem = parseInt( $(this).data('ref') );

  if ($(this).text()==='back')                             // level Up
  {
    List_Level.pop()
    ShowList_F();
  }
  else if (current_List[xItem].hasOwnProperty('children')) // level Down (and same test)
  {
    List_Level.push(xItem);
    ShowList_F();
  }
})
#my-List { cursor: pointer; list-style-type:none }
.PLUS::before { content: '- '}
.PLUS:hover::before { content: '+'}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<ul id="my-List"></ul>

0
ответ дан MrJ 18 March 2019 в 00:10
поделиться
Другие вопросы по тегам:

Похожие вопросы: