这个问题通常是由于在PHP中使用了MySQLi OO接口中的错误语法导致的。要解决这个问题,首先你要确认在调用mysqli_stmt_execute函数之前已正确设置了bind_param参数,然后将查询结果为对象的方式改为数组方式即可。下面是一个示例代码:
PHP代码片段:
$stmt = $mysqli->prepare("SELECT title FROM posts WHERE author=?"); $stmt->bind_param("i", $author_id); $stmt->execute(); $result = $stmt->get_result(); $data = $result->fetch_all(MYSQLI_ASSOC);
JavaScript代码片段:
$.ajax({ url: 'ajax_test.php', data: {author_id: 1}, dataType: 'json', success: function(response) { console.log(response.data); }, error: function(response) { console.log('Error: '+response.responseText); } });
在上述示例代码中,$data数组将存储查询结果,而JavaScript中的ajax请求也通过设置dataType为“json”来正确解析返回的结果。