Your problem is that the ''
of his arguments, correcting his code he gets like this :
echo ' <button type="button" class="btn btn-link btn-comentario-reposta" id="botao-esconde-resposta-'.$_POST['id'].'"
onclick="acao_botao_esconde_resposta(\''.$_POST['id'].'\',\''. $btn_mostrar_resposta .'\')">Esconder respostas</button>';
How it works :
To escape some special character like ""
the quotation marks or ''
simple quotes we use to pass arguments within the functions we use the \
backslash so that in the code it considers the character as part of the string, an example that can best sclacer is the following :
$id = $_POST['id'];
$email = $_POST['email'];
$html = '<button id="btn-'.$id.'" onclick="func_teste('.$id.','.$email.')"></button>';
echo $html;
This example would be your case where the error happens and why ? Well when this code goes to html it will be generated this way for example:
<!-- código html -->
<button id="btn-1" onclick="func_teste(1,[email protected])"></button>
<!-- código html -->
As we can see the parameter passage is wrong and so your code is printing )">Esconder respostas
to avoid this problem has to put the \"\"
quotation marks or quotes \'\'
Simple quotes to make your escape and so they become literal.
$id = $_POST['id'];
$email = $_POST['email'];
$html = '<button id="btn-'.$id.'" onclick="func_teste(\''.$id.'\',\''.$email.'\')"></button>';
echo $html;
And the result will be like this :
<!-- código html -->
<button id="btn-1" onclick="func_teste('1','[email protected]')"></button>
<!-- código html -->
that
echo
is the result of your ajax ?– Vinicius Shiguemori
echo will be returned to ajax to write to html.
– Murilo Haas