I am sending a simple array from my PHP file,
//example.php
if(0){
return json_encode(['status'=>false, 'message'=>'Please enter a username']);
}
and in my ajax.js
I have everything working, including the XHR object, and event handlers. All is find, except this line.
// ...
var x = JSON.parse(xmlhttp.responseText);
console.log(x);
// ...
But, I am getting the following error.
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
I don't understand this. All the code is correct. Before using JSON, I used to pass from values from PHP using echo 'ok'
and just do if(xmlhttp.responseText) == 'ok
and it worked fine, but not with json