以下php运行良好。然而,当您向php添加print_r
或echo
以查看任何变量时,它会发送以下错误:
SyntaxError:JSON.parse:后面的意外非空格字符 JSON数据的第1行第83列的JSON数据
foreach ($ChangingMap as $key => $value){
$SqlVariables[$key]=array(
'id' => $ChangingMap[$key]['element_id'],
'action' => $ChangingMap[$key]['e_action'],
'record' => $ChangingMap[$key]['e_record'],
'table' => $ChangingMap[$key]['e_table'],
'ascendant' => $ChangingMap[$key]['ascendant'],
'where' => $ChangingMap[$key]['descendant']
);
if ($ChangingMap[$key]['status']==$Basic_Status[0]){
for($i=0;$i<sizeof($Variable_holder);$i++){
$carrier=explode("|", $ChangingMap[$key][$Variable_holder[$i]]);
$SqlVariables[$key][$Query_Variable_holder[$i]]=$carrier[0];
}
$SqlVariables[$key]['where']=$Query_Destination[0];
}
$SqlQuery[$key]= $SqlVariables[$key]['action'].' '.$SqlVariables[$key]['record'].' FROM '.$SqlVariables[$key]['table'].' WHERE ' .$SqlVariables[$key]['where'].'="'.$ChangingArr[1].'"';
$SqlArray[]=array(
'id' => $ChangingMap[$key]['element_id'],
'sql'=> $SqlQuery[$key]
);
$ClearStr='';
$test=CallData('Changing',$SqlArray[$key]['id'],$SqlArray[$key]['sql'],$ClearStr);
}
}
//print_r($test);
echo json_encode($test);
}
javascript函数如下
function Administrator(){
$(document).on('change',function(e){
if(e.target.tagName ==="SELECT"){
ChangingSelect="Changing|"+e.target.id+"|"+$( '#' +e.target.id + ' option:selected' ).text();
//console.log(ChangingSelect);
$.ajax({
type: "POST",
url: "ChangingTool.php?ChangingSelect="+ChangingSelect})
.done(function(data){
var Mydata = JSON.parse(data);
console.log("hi");
$.each(Mydata, function (i,item) {
var SelectedDataArr=Mydata[i].selected.split('|').filter(function(x){return (x !== (undefined || null || ""));});
$('#'+Mydata[i].id).empty();
$.each(SelectedDataArr,function(j,item){
$('#'+Mydata[i].id).append('<option value="' + j + '">'+ SelectedDataArr[j]+'</option>');
});
});
});
}
});
}
如何克服这个问题?它限制了我测试变量的能力。