-1
Hello I’m new in these code things and wanted to know how I make to appear the success message after I give Submit, I want those messages that appear the green field, like a div and edit with css. And I also wish that after giving Submit appear another button like a download button
Index.php
<!DOCTYPE html>
<html>
<head>
<meta "charset=utf-8" />
<title>Cadastro</title>
<link rel="stylesheet" type="text/css" href="assets/css/theme.css" />
<script src="assets/js/jquery.js"></script>
<!--Arquivo Ajax-->
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#ajax_form').submit(function() {
var dados = jQuery(this).serialize();
jQuery.ajax({
type: "POST",
url: "newsletter-form.php",
data: dados,
success: function envio() {
var cont = "Email enviado com sucesso";
document.getElementById("msg").innerHTML = cont;
}
});
return false;
});
});
</script>
</head>
<body>
<div class="for" <div class="container">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<form id="ajax_form" name="signup" method="post" action="cadastro.php">
<div class="form-group">
<input type="text" id="name_user" class="form-control" name="nome" required placeholder="Seu nome" />
</div>
<div class="form-group">
<input type="email" id="email_user" class="form-control" name="email" required placeholder="Seu email" />
</div>
<div class="form-group">
<input type="tel" id="telefone_user" class="form-control" name="telefone" required placeholder="Seu telefone" />
</div>
<button class="btn btn-primary btn-block btn-register">
Enviar
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Thank you very much John, but and the javascript codes I put where?
– Leonardo
Inside the tag
<script>
that you were actually using. Although, as your code grows, it is interesting you use an external file for JS code and call it in html using<script src="arquivo.js"/>
for example– João Pedro Henrique
Dude I click the button and don’t go out of place
– Leonardo
Did you at least manage to request the server, i.e., send the data? If so, the button is gone and everything? Did you insert the CSS as well? When I tested it here - using another URL just to pass the request - it worked normally.
– João Pedro Henrique
The button isn’t gone, it doesn’t go anywhere I click on Ubmit and it doesn’t change anything
– Leonardo
Right, but did the request pass or not? Do the following, change the line
success: function envio() {
forsuccess: function envio(data) { console.log(data)
send Ubmit and see if the request is succeeding. Next to this, addtype='submit'
on the send button.– João Pedro Henrique
i did it but it had no change, you have whatss? c if it has leave the number here I call you there
– Leonardo
I don’t know how it’s not going, because it worked and mine didn’t
– Leonardo
Weird. Did you do that thing I said and nothing showed up on the console? If it did not appear, for some reason the request is not passing, or else it is not being called.
– João Pedro Henrique
This error appeared in the console POST http://localhost/Notflix2/php/nueva/newsletter-form.php 404 (Not Found) send @ jquery.min.js:4 ajax @ jquery.min.js:4 (Anonymous) @ config.js:15 Dispatch @ jquery.min.js:3 r. Handle @jquery.min.js:3
– Leonardo
The error is in the request. It is returning you that the page does not exist. This is actually the URL of the api that you are making the request?
– João Pedro Henrique
I changed and says I successfully sent the email, but on the console appears this error Uncaught Typeerror: Cannot set Property 'innerHTML' of null at Object. [as Success] (((index):40) at j (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at x (jquery.min.js:4) at Xmlhttprequest.<Anonymous> (jquery.min.js:4) send@(index):40 j @jquery.min.js:2 fireWith @jquery.min.js:2 x @jquery.min.js:4
– Leonardo
But the message appeared "Email sent"
– Leonardo
It’s because you div her with id
msg
does not exist. But otherwise, everything normal.– João Pedro Henrique
Oxe, who ever saw? kkk and I do what?
– Leonardo
You can delete these two lines:
var cont = "Email enviado com sucesso"; document.getElementById("msg").innerHTML = cont;
– João Pedro Henrique
Now it worked dude haha vlw dude you deserve everything
– Leonardo
Mark thread as answered there ;)
– João Pedro Henrique