So, following some advice earlier I wanted to create a email form where after you submit a valid e-mail the signup box disappears and a new message appears saying 'Thanks for signing up' or something along those lines. I got the validation down. And my process.php works. Also, #message gets hidden, but the page redirects right afterwards and in the address bar it shows: www.myurl.com/?address=wahteveriinputed@whatever.com
Here is my jquery code regarding the posting:
function stateChanged3 () {
}
function GetXmlHttpObject () {
var requestObj = null;
if (window.XMLHttpRequest)
requestObj = new XMLHttpRequest();
else if (window.ActiveXObject)
requestObj = new ActiveXObject("Microsoft.XMLHTTP");
return requestObj;
}
requestObj3 = GetXmlHttpObject();
var url = "mlml/process.php?address=" + emailaddressVal;
requestObj3.open("POST", url, true);
requestObj3.onreadystatechange = stateChanged3;
requestObj3.send(null);
$('#message').toggle();
my php code is pretty simple it's a modified open source mailer is as follows:
$email = $_REQUEST["address"];
$key = md5(time());
$req_time = time();
$query = "SELECT * FROM `mailinglist_subscribers` WHERE `address` = '$email'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows != 1) {
$query = "INSERT INTO mailinglist_subscribers VALUES ('$email', '$key', '1', '$req_time', '0')";
$result = mysql_query($query) or die("Query failed : " . mysql_erro开发者_如何转开发r());
}
- use a javascript library (like jquery to do the ajax call), it would make your life easier.
- use onclick, or tap to click event, not stateChanged event, and return false in the event handler.
- set the callback for the ajax call to do things like: hide signup box and show new message.
精彩评论