相关疑难解决方法(0)

从$ _POST中的json读取关联数组

我正在使用jQuery将json对象发布到我的php应用程序.

jQuery.post("save.php",JSON.stringify(dataToSend), function(data){ alert(data); });
Run Code Online (Sandbox Code Playgroud)

从萤火虫中拉出的json字符串看起来像这样

{ "data" : [ { "contents" : "This is some content",
        "selector" : "DIV.subhead"
      },
      { "contents" : "some other content",
        "selector" : "LI:nth-child(1) A"
      }
    ],
  "page" : "about_us.php"
}
Run Code Online (Sandbox Code Playgroud)

在PHP中我试图将其转换为关联数组.

到目前为止,我的PHP代码是

<?php
$value = json_decode(stripcslashes($_POST));
echo $value['page'];
?>
Run Code Online (Sandbox Code Playgroud)

对ajax调用的响应应为"about_us.php",但它返回空白.

php post json associative-array http-post

18
推荐指数
2
解决办法
7万
查看次数

标签 统计

associative-array ×1

http-post ×1

json ×1

php ×1

post ×1