Hello!

The server generates a string in the form of html code. For example:

$html = '<div class="cats"></div>'; 

Can this data be sent as JSON?

Using:

 echo json_encode($html); 

It turns out:

 "<\/div>" 
  • so everything is OK, although you can send it as html just by typing the input data as html in the function ajax , post , get if it is jquery. - Naumov
  • @Naumov, It is necessary in JSON to send additional data for the js script - Pavel
  • Yes, and so it goes in the answer will not be taken into account characters shielding ie result.html will return acceptable text. - Naumov

1 answer 1

 $html = '<div class="cats"></div>'; $a = json_encode($html); $b = json_decode($a); print_r($b); 

At the output in the $b variable, we have '<div class="cats"></div>'; On the receive side, use json_decode . Checked here