我有一个存储在 mongoDB 集合中的 JSON 对象。该对象表示 5 x 图像、5 y 图像和 tictactoe board 图像的位置。
每隔一段时间,我向一个用这个对象响应的 php 文件发送一个请求,然后我想解析那个对象并相应地移动这些片段。
这是我的要求:
$.getJSON
(
"e4.php",
"",
function(data)
{
world = JSON.parse(data);
moveObjects(world);
}
);
但我得到:JSON.parse:意外字符
当我 console.log 数据时,萤火虫给了我正确的对象,所以我知道它正在正确返回。
在 e4.php 中:
$criteria = array("name" => "world");
$doc = $collection->findOne($criteria);
$conn->close();
print $doc['world'];
其中 conn 是连接,而 collection 是我正在使用的集合。
数据库在 e3.php 中更新:
$encodedworld = $_REQUEST['data'];
$criteria = array("name" => "world");
$doc = $collection->findOne($criteria);
$doc['world'] = $encodedworld;
$collection->save($doc);
$conn->close();
print $encodedworld;
有任何想法吗?我很难过
提前致谢。