This is probably very simple, but I'm really in over my head. Basically, I have a form with one input: email, and a submit button. This was not done by me so I understand very little of it. I tried to look up the .ajax jQuery command, but it still makes no sense.
Basically, here is what I have on the index.php.
The JS and HTML:
<!-- Subscription -->
<script>
$(function() {
$('form input.submit').click(function (event) {
event.preventDefault();
event.returnValue = false;
$.ajax({
type: 'POST',
url: 'subscribe.php',
data: {email: $('form input[type=email]').val()},
success: function(data) {
开发者_运维问答 if (data == 'successful') {
$('#subscribe_status').html('Thanks for subscribing! We will let you know.').slideDown();
} else if (data == 'already_subscribed') {
$('#subscribe_status').html('This email is already subscribed.').slideDown();
} else if (data == 'invalid_email') {
$('#subscribe_status').html('This email is invalid.').slideDown();
} else {
$('#subscribe_status').html('Something went wrong. Please try again.').slideDown();
}
},
error: function () {
$('#subscribe_status').html('Subscription is not available.').slideDown();
}
});
});
});
</script>
<form action="#">
<input type="email" value="Your e-mail address..." onfocus="value=''" />
<input type="submit" class="submit" value="Notify me" />
</form>
Subscribe.php
include 'go.php';
$email = $_POST['email'];
$ip=$_SERVER['REMOTE_ADDR'];
$timestamp = date("m/d/y H:i A");
mysql_query("INSERT INTO subscribers (ip, email, timestamp) VALUES (INET_ATON('$ip'), '$email', '$timestamp') ") or die(mysql_error());
I basically just keep getting "Something went wrong. Please try again."
Subscribe.php
doesn't return anything, so data
in your JS is always emtpy, hence the last else is always executed.
精彩评论