我遇到了以下问题..我正在尝试使用Ajax从我的数据库中检索一些信息,但是,当我尝试通过分析mysqli_object中的信息来调试它时,我的查询失败了,所有的属性为null:
我打印了控制台对象的内容:
affected_rows:null
client_info:null
client_version:null
connect_errno:null
connect_error:null
errno:null
error:null
error_list:null
field_count:null
host_info:null
info:null
insert_id:null
protocol_version:null
server_info:null
server_version:null
sqlstate:null
stat:null
thread_id:null
warning_count:null
为什么会发生这种情况?
这是我的Ajax电话:
$('#npClientName').keyup(function(){
var txt = $(this).val();
if (txt == "") {
$('#npClientList').fadeOut();
return false;
}
$.ajax({
method: 'POST',
url: '/fitcoControl/Resources/PHP/Clientes/fetchPopupClientList.php',
data:{txt: txt},
success: function(result){
rsp = JSON.parse(result);
console.log(rsp);
if (rsp.code != "1") {
$('#npClientList').html("<p>Hubo un error al cargar la lista de clientes...</p>");
console.warn("Error en el query: " + rsp.response);
} else {
$('#npClientList').html(rsp.response);
}
$('#npClientList').fadeIn();
clientSelector();
},
error: function(exception){
console.error(exception);
}
});
});
这是我的PHP代码:
$root = $_SERVER['DOCUMENT_ROOT'];
$data = array(
'code'=>"",
'response'=>""
);
$txt = "'%" . $_POST['txt'] . "%'";
require $root . "/fitcoControl/Resources/PHP/DataBases/Conexion.php";
$query = "SELECT * FROM ct_cliente";
$stmt = $conn->prepare($query);
//$stmt->bind_param('s', $txt);
$stmt->execute();
$resultados = $stmt->get_result();
$num_rows = $stmt->num_rows;
if (false) {
$data['code'] = 2;
//$data['response'] = $num_rows;
} else {
$data['code'] = 1;
$data['system'] = $conn;
while ($a = mysqli_fetch_assoc($resultados)) {
$idCliente = $a['pk_cliente'];
$nc = $a['nombreCliente'];
$data['response'] .= "<p client-id='$idCliente'>$nc</p>";
}
}
$json = json_encode($data);
echo $json;
想法?