由于之前的计算机开始疯狂,我只是将我的代码从一台计算机交换到另一台计算机。现在,当我尝试使用我的网站时,它不会将任何信息提取到div中。我真的不确定这里发生了什么,它给了我一个错误
未捕获的SyntaxError:意外的令牌<在JSON的第2位JSON.parse()
我之前没有得过的。<script>
//$('#agent').change(function(){
$(document).on('change', "#agent", function(event) {
//jquery
var IEX_ID=$(this).val();
if (IEX_ID){
//ajax call
$.ajax({
type:'POST',
url:'GetAllData.php',
cache:false,
data: 'Fullname='+IEX_ID,
success: function(data){
var obj = JSON.parse(data);
console.log(obj);
$('#IEX_ID').html(obj.IEX_ID);
$('#BalancedScore').html(obj.BalancedScore);
$('#CustomerEx').html(obj.CEPt);
$('#CEM1').html(obj.CEM1);
$('#CEM2').html(obj.CEM2);
$('#CEM3').html(obj.CEM3);
$('#CETlabel').html(obj.CET1);
$('#CET2label').html(obj.CET2);
$('#CET3label').html(obj.CET3);
</script>
下面是从中拉出数组的php。如果我做控制台日志,它会给我“尝试获取非对象的属性'num_rows'”这通常意味着我的查询存在问题。我没有发现任何问题?它与在另一台计算机上使用的完全相同的代码。我只是复制所有文件并传输它们以查看是否修复了任何问题。我不确定为什么一台计算机上的一切都完美无缺,但在这一台计算机上却给了我这些错误。
<?php
$Fullname=$_POST['Fullname'];
if(!empty($_POST['Fullname']))
{
$query=$conn->query("SELECT Supervisor, Fullname, IEX_ID, BalancedScore, CEPt, CEM1, CEM2, CEM3, FCRPt, FCRM1, FCRM2, AIMPt, AIMScore, AIMCnt, ProdPt, CET1, CET2, CET3, FCRT1, FCRT2, AYHT, AYHM, M_AYHT, AYHPt, Total, skill1, skill2, skill3, skill4, skill5, skill6, skill7, skill8, skill9, skill10, skill11, skill12, skill13, skill14, skill15, skill16, skill17, skill18, skill19, IncentiveMonth FROM CurrentSC WHERE IEX_ID = '".$Fullname."' order by Fullname ASC ");
$rowCount=$query->num_rows;
if($rowCount>0)
{
while($row = mysqli_fetch_array($query))
{
echo json_encode;
$output = array ("IEX_ID" => $row['IEX_ID'], "BalancedScore" => $row['BalancedScore'], "CEPt" => $row['CEPt'], "CEM1" => $row['CEM1'] , "CEM2" => $row['CEM2'], "CEM3" => $row['CEM3'], "FCRPt" => $row['FCRPt'], "FCRM1" => $row['FCRM1'] ,"FCRM2" => $row['FCRM2'],"AIMPt" => $row['AIMPt'],"AIMScore" => $row['AIMScore'],"AIMCnt" => $row['AIMCnt'],"ProdPt" => $row['ProdPt'],"CET1" => $row['CET1'] ,"CET2" => $row['CET2'],"CET3" => $row['CET3'],"FCRT1" => $row['FCRT1'],"FCRT2" => $row['FCRT2'],"AYHT" => $row['AYHT'],"AYHPt" => $row['AYHPt'],"M_AYHT" => $row['M_AYHT'],"AYHM" => $row['AYHM'],"Total" => $row['Total'],"skill1" => $row['skill1'],"skill2" => $row['skill2'],"skill3" => $row['skill3'],"skill4" => $row['skill4'],"skill5" => $row['skill5'],"skill6" => $row['skill6'],"skill7" => $row['skill7'],"skill8" => $row['skill8'],"skill9" => $row['skill9'],"skill10" => $row['skill10'],"skill11" => $row['skill11'],"skill12" => $row['skill12'],"skill13" => $row['skill13'],"skill14" => $row['skill14'],"skill15" => $row['skill15'],"skill16" => $row['skill16'],"skill17" => $row['skill17'],"skill18" => $row['skill18'],"skill19" => $row['skill19'],"IncentiveMonth" => $row['IncentiveMonth']);
echo json_encode($output);
}
}
}
?>
答案 0 :(得分:0)
未捕获的SyntaxError说: 意外的令牌&lt;在JSON的第2位JSON.parse()
这意味着网址:'GetAllData.php' 可能会返回PHP错误。这可能是数据库,PHP更新,缺少函数等......当我的PHP源格式错误时,我看到同样的错误。
QED:检查website.com/GetAllData.php的结果,看看它们是否是正确的JSON。