Exemple
{"title":"<p>gfgfgfest<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\">"}
Erreur (en JS):
Unexpected token h in JSON at position 68
Cordialement{"title":"<p>gfgfgfest<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\">"}
Erreur (en JS):
Unexpected token h in JSON at position 68
Cordialement
json_encode($data);
Disons que je fait seulement ca:
<?php $data['title'] = '<math xmlns="http//:www.w3.org/1998/Math/MathML">';
Puis que je le converti comme tantôt, cela me fait la même erreur... Si quelqu'un a eu une idée, je suis prenant
<?php
$data['title'] = '<math xmlns="http//:www.w3.org/1998/Math/MathML">';
// transformation en JSON
$json_data=json_encode($data);
// Affichage du JSON
echo htmlentities($json_data);$testjson['title'] = '<math xmlns="http//:www.w3.org/1998/Math/MathML">';
Puis en js:
var data = JSON.parse('<?php echo json_encode($testjson) ?>');
Ce qui est affiché au client est:
var data = JSON.parse('{"title":"<math xmlns=\"http\/\/:www.w3.org\/1998\/Math\/MathML\">"}');
Et j'obtiens cette erreur:
Uncaught SyntaxError: Unexpected token h in JSON at position 23
Cordialement
$testjson['title'] = addslashes('<math xmlns="http//:www.w3.org/1998/Math/MathML">');
De cette manière cela me donne:
{"title":"<math xmlns=\\\"http:\/\/www.w3.org\/1998\/Math\/MathML\\\">"}
et ça passe !