hi i have a page contains a link , when user click the link i want to go to database and retrieve two arrays , but when i alert those two arrays i got this exception
Unexpected token [
this is my js code
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();
}
and this is my php code
public function getRelatedConceptsAndRelations($concpetName, $Ajax) {
if ($Ajax) {
$concepts = array('c1', 'c2');
$relations = array('r1','r2');
echo json_encode($concepts);
echo json_encode($relations);
}
return;
}
why is this exception ? and how can i solve it ? and how can i receive those two arrays in my js ?
this is full code code
When you response a JSON, it needs to be one JSON, but you are sending two seperate arrays.
Merge those two JSONs into one.
Update:
Do it like this: