Nati Aizikovitz Posted October 31, 2019 Share Posted October 31, 2019 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. Link to comment Share on other sites More sharing options...
Ingolme Posted October 31, 2019 Share Posted October 31, 2019 Your PHP code is calling an undefined function, so it's showing an error message which is not valid JSON. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now