I need a JavaScript variable like:
var test_js = {
"first_test": "a_simple_test",
"second_test": "other_simple_test",
"last_test": "last_simple_test"
};
But the array is returned using ajax, i'm trying:
test.php
echo "
'first_test': 'a_simple_test',
'second_test': 'other_simple_test',
'last_test': 'last_simple_test'
";
JavaScript
$.post("test.php").done(function(test_data) {
var test_js = {
test_data
};
});
But when i'll minify the JavaScript (jscompress.com)
The following error is returned:
Unexpected token punc «}», expected punc «:»
How to do to fix it and return the array correctly?
Aucun commentaire:
Enregistrer un commentaire