我正在尝试使用php通过javascript来编辑数据查询,
我的ajax请求看起来像这样
var totalSearchResult=10;
$.ajax({
url:"php/queryManipulation.php",
type: 'POST',
data: { totalQuery : totalSearchResult, query : '{"data":{"match_all":{}}}'},
success: function(finalList)
{
alert(finalList);
}
});我的php代码看起来像这样
<?php
$from=$_POST["totalQuery"];
$qry=json_decode($_POST["query"]);
$qry->from=$from; }?>我试着把它写进表格里,
{"data": {"match_all": {}} , "from": 10}我得到错误Object of class stdClass could not be converted to string
发布于 2012-07-24 16:34:44
您可以解码为一个数组(不确定对象),然后重新编码:
$qry = json_decode($_POST['query'], TRUE);
$qry['from'] = 10;
$new_qry = json_encode($qry);https://stackoverflow.com/questions/11627032
复制相似问题