Please help, when sending a JavaScript variable containing HTML code, using the post method ajax

var text = "<span style = 'color: red;'></span>"; $.ajax({ url: "edit.php", type: "POST", datatype: "html", data: ({text}), success: div_edit }); 
 <? $text = $_POST["text"]; echo $text; // в index.php выводится это <span style = "\"color:" red;\"></span> ?> 

 <span style = 'color: red;'></span> 

turns into

 <span style = "\"color:" red;\"></span> 

How can this be prevented? Code:

  • Obviously, it depends on how you send and how you read later - andreymal
  • In more detail write the code. - Drakonoved
  • PHP code appeared - progress) But still, how do you read the $text variable? - andreymal
  • You have some strange quotes. Maybe you should write like this: "<span style = 'color: red;'></span>" - Drakonoved
  • @Drakonoved, however, “\” cannot turn out from these quotes, the author still does not finish speaking - andreymal

0