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);

 

posted on 2013-08-29 16:42  any91  阅读(1163)  评论(0编辑  收藏  举报