T
T
Tokenchik2018-02-04 19:01:40
PHP
Tokenchik, 2018-02-04 19:01:40

How to fix json?

Collecting json for ajax request. Html markup makes it invalid, how to solve this problem?

$response = array(
            "html" => $template,
            "show" => 'true'
        );
      header('Content-type: application/json; charset=utf-8');
      $json = json_encode($response );

If I remove the html data in the array, then everything is fine, and ajax calmly parses everything. The error is from PHP.
In this form, for some reason, he does not understand in any way.
5a7737e959988181686239.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-02-04
@Tokenchik

The only thing you can see is the quote conflict - HTML itself uses double quotes, and it's also wrapped in double quotes. Try like this
$json = json_encode($response, JSON_HEX_QUOT);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question