php code:
$array = array($variable-1, $variable-2, $variable-3, ….. variable-n);
echo jason_encode($array);
javascript code:
var ar = new XMLHttpRequest();
ar.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var obj = JSON.parse(this.responseText);
document.forms["form1"]["fnameMsg"].value = obj[0];
document.forms["form1"]["lnameMsg"].value = obj[1];
document.forms["form1"]["mphoneMsg"].value = obj[2];
}
}
The above code create an error:
Uncaught SyntaxError: Unexpected token < in JSON at position 0
Can someone help me to understand what is wrong with the above code and how to correct it.
Thanks.