6
I am developing an application that uses PHP + AJAX and I came across an annoying problem. AJAX only recognizes the function if it is like this:
onclick="remover_musica_ftp('0','Deposito de bebida'
);"
I’m using PHP to "print" these values in the browser like this:
echo "<a href='#excluir' class='button icon-trash' onclick=remover_musica_ftp('0','".$nomes."'); title='Excluir'></a>";
I have to use php because I’m making one foreach
.
So far so good, the problem is that when the word contains spaces, ajax simply does not respond, because the code would need to be like in the first example, only when I add the quote "
automatically PHP becomes invalid, as the same echo
started with an quotation mark.
Does anyone know what I should do in this case?
If I open the echo with a '
error the same way, because it would need to invert the ajax onclick that would not allow the '
in office.
Give me a suggestion!
You need to escape the quotation marks so that PHP realizes that this "quotation mark" is not for PHP. Test like this:
echo "<a href='#excluir' class='button icon-trash' onclick='remover_musica_ftp(\"0\",\"".$nomes."\");' title='Excluir'></a>";
– Sergio
I don’t know if it will, but this part,
('0','".$nomes."')
, can be written as('0','$nomes')
. PHP parses the variable when it is inside double quotes.– brasofilo
But no need to double quote string?
– Papa Charlie