嗨,我有一个页面包含一个链接,当用户单击该链接时,我想去数据库并检索两个数组,但是当我提醒这两个数组时,我得到了这个异常
Unexpected token [
这是我的js代码
function acNewConcpet(element){
var parent = element.parentNode;
parent.removeChild(element);
var concpetSelect = document.createElement('select');
var relationSelect = document.createElement('select');
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var data = JSON.parse(xmlhttp.responseText);
alert(data);
}
}
xmlhttp.open("GET","http://localhost/Mar7ba/Ontology/getRelatedConceptsAndRelations/"+"concept"+"/TRUE",true);
xmlhttp.send();
}
这是我的 php 代码
public function getRelatedConceptsAndRelations($concpetName, $Ajax) {
if ($Ajax) {
$concepts = array('c1', 'c2');
$relations = array('r1','r2');
echo json_encode($concepts);
echo json_encode($relations);
}
return;
}
为什么这个例外?我该如何解决?以及如何在我的 js 中接收这两个数组?这是完整的代码