I have a script that "remember" the values in the input fields after a submit.
var previousData = <? php echo json_encode($_POST, JSON_UNESCAPED_UNICODE); ?> ;
for (item in previousData) {
if (previousData.hasOwnProperty(item)) {
// Set the value to the input with same name
$('input[name=' + item + ']').val(previousData[item]);
$('select[name=' + item + ']').val(previousData[item]);
}
}
The problem is that I get a syntax error:
SyntaxError: syntax error
var previousData = ;
When I remove JSON_UNESCAPED_UNICODE
, it works perfect. Why?