PHP通过JSON给JS赋值;JS通过JSON给PHP传值

$fileNames = array(); // 是数组,不是字符串
$filesJSON = json_encode($fileNames);// 转成json格式
var oldFiles = new Array();

//oldFiles = '<?php echo $filesJSON;?>';// 这样oldFiles成字符串了,而不是json数据
oldFiles = JSON.parse('<?php echo $filesJSON;?>');// JSON格式即为数组格式

 -------------------------------------------------------------------------------------------------

    var jsonProps = {
        "dispMode":dispMode,
        "autoRun":autoRun,
        "remark":remark
    };

    $.ajax({
         url:"./process/writeTask.php",
         data:"proType=setTask&taskId=" + taskId + "&props=" + JSON.stringify(jsonProps),
$props = json_decode($_REQUEST['props'], true);
原文地址:https://www.cnblogs.com/any91/p/3289464.html