Uczę się jQuery i AJAX'u lecz jestem na etapie tworzenia tak zaawansowanej strony, stoję przy funkcji email. Mam pytanie - czy da się zrobić aby email został wysłany w taki sposób aby strona nie musiała się przeładowywać ?
Pozdro
function cos() { $.ajax({ url: "mail.php", data: "email=aa@aa.pl&tresc=tresc" type: "POST", success: function(zwrot){ alert(zwrot) }, error: function(){ alert('blad') } } }); }
<input type="submit" onclick="cos();">
$(function(){ $('#idformularza').submit(function(){ $.ajax({ url: "mail.php", data: $(this).serialize(), type: "POST", success: function(zwrot){ alert(zwrot) }, error: function(){ alert('blad') } }); return false; }); })
<form id = "idformularza"> reszta forma z submitem
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <form action="/" id="forma" method="POST"> <input type="text" name="od" value="Od kogo" onclick="this.value=''"><br> <input type="text" name="temat" value="Temat" onclick="this.value=''"><br> <input type="text" name="wiadomosc" value="Wiadomosc" onclick="this.value=''"> <input type="submit" name="przycisk" value="Wyslij" /> </form> <script> $(function(){ $('#forma').submit(function(){ $.ajax({ url: "index.php?s=a", data: $(this).serialize(), type: "POST", success: function(){ alert("ss") }, error: function(){ alert('blad') } }); return false; }); }) </script> </body> </html> <?php if($_GET["s"] == "a"){ $odkogo = $_POST["od"]; $temat = $_POST["temat"]; $mess = $_POST["wiadomosc"]; $naglowki = "Reply-to: tech@mail.pl <tech@mail.pl>".PHP_EOL; $naglowki .= "From: tech@mail.pl <tech@mail.pl>".PHP_EOL; $naglowki .= "MIME-Version: 1.0".PHP_EOL; $naglowki .= "Content-type: text/html; charset=iso-8859-2".PHP_EOL; $wiadomosc = $mess; { } } } ?>
<?php // The message $message = "Line 1\nLine 2\nLine 3"; // In case any of our lines are larger than 70 characters, we should use wordwrap() // Send ?>