1
I am trying to send the content of a textarea to another page, as code below:
<textarea id="mensagem" rows="8" cols="100" maxlength="500" style="border-radius: 6px; resize:none;width: 90%;height: 65px; margin:0 auto;">
ESCREVA ALGO AQUI
</textarea>
<button type="button" class="btn btn-success" id="sendMSG">Enviar</button>
<script>
$(document).ready(function(){
$("#sendMSG").click(function(){
var url = "enviamsg.php";
var email = "<?php echo $_SESSION['email']?>";
var msg = $('#mensagem').val();
alert("teste");
$.post(url,{postemail:email,postmsg:msg},
function(result) {
$("#result").html(result); // Só pra verificar retorno
});
});
});
</script>
When you click the button, nothing happens. I imagine the problem is in the button call as I have tried to comment on a few lines and leave only a few Alerts, and yet nothing happened. Someone would know where I’m going wrong?
Thank you.
It may be some syntax error, in the browser console, some error is shown?
– cbonomini
I used your same code with a
enviamsg.php
returning always 1 and worked correctly. I only created onediv
idresult
and I set the e-mail to not read the session.– cbonomini
Have you added jquery to your code? checked if the url is going to the Cero path, because you did not specify the absolute path of the site tested here is everything working https://jsfiddle.net/f5jchgz9/ remember the code has to come after jquery and put the absolute url of your site example.com/enviar.php
– user28266
the problem was that it was missing to include the jquery code at the top of the page... were of great help, thank you very much !
– Vitor de Oliveira