渡すphpファイルに渡そうとする配列がありますが、配列が文字列として表示されます。文字列を配列に変換してphpで処理できるようにするにはどうすればよいですか? これが私のコードです:
jQuery
$('#add-child').click(function()
{
var _attributes = [];
$('#attributes input').each(function()
{
_attributes.push($(this).val());
});
$.post('../assets/hub.php',{'task':'add-child','parent':$('#parent-id').val(),'value':$('#child-value').val(),'attributes':JSON.stringify(_attributes)},function(callback)
{
console.log(callback);
});
});
PHP
case 'add-child':
$department = $_POST['parent'];
$category = $_POST['value'];
$attributes = $_POST['attributes'];
print($department.' : '.$category.' : '.$attributes);
break;
電流出力
test1 : test2 : ["sdfg","34","vsdf"]
** 編集 **
私は削除JSON.stringify()
して追加var_dump()
しました。これが出力です:
string(3) "114"
string(4) "asdf"
array(3) {
[0]=>
string(4) "asdf"
[1]=>
string(4) "ZVCX"
[2]=>
string(5) "asdfr"
}