我正在使用jquery ajax调用
var data="name"+get_name;
$.ajax({
type:"GET",
url:"php/getAllInfo.php",
data:data,
dataType:"json",
success: function(data){
var allDetails=data;
console.log(allDetails);
},
error:function(jqXHR, textStatus, errorThrown){
console.log(errorThrown);
},
complete: function(){
}
});
PHP
$name = trim($_GET['name']);
$mysql_resultset = mysqli_query($con, "SELECT dod.deviceId, drs.cpuUtilization FROM device_owner_details dod, device_realtime_stats drs WHERE dod.name = '$name' AND drs.deviceId= dod.deviceId ");
$rows_data = mysqli_fetch_assoc($mysql_resultset);
$all_details = array('deviceId'=> $rows_data['deviceId'], 'cpuUtilization' => $rows_data['cpuUtilization']);
$response = json_encode($all_details);
echo $response;
mysqli语句是正确的。但是它给出了语法错误,编码中的错误是什么。这里cpuUtilization值为NULL
我想要{deviceId:' idvalue',cpuUtilization:' value'}
等信息答案 0 :(得分:0)
Edit var data="name"+get_name;
至var data="name="+get_name;
检查您的响应,如果响应不在json或json无效,则发生错误