i am trying for hours now, cant get it to work
my ajax call
$('.button').click( function() {
var mail = $("#mail_content").val();
alert(mail);
$.ajax({
type: "POST",
url: "process.php",
data: "mail="+ mail,
success: function(){
alert("success");
}
});
});
my process.php
<?php
// echo "<pre>";
// print_r($_POST);
// echo "</pre>";
include 'config.php';
include 'lib.php';
$db = dbConnect();
$mail = quote_smart($_POST['mail']);
//insert, update, select, delete
$query = "INSERT INTO mail VALUES ('', '$mail')";
$result = insertQuery($query);
dbClose($db);
echo "entry saved";
?>
my form
<div class="email">
<div class="email_title">GET NOTIFIED FOR THE GRAND OPENING<br /> </div>
<div id="contact_form">
<form id="mail" name="mail" action="" method="post" enctype="multipart/form-data">
<fieldset>
<label for="mail" id="email_label">YOUR EMAIL</label>
<input type="text" name="mail_content" id="mail_content" size="30" value="" class="text-input" />
<input type="submit" name="submit" class="button" id="submit_btn" value="SAVE" />
</fieldset>
</form>
</div>
</div>
am i overlooking something? it works when i put the process.php code in the action in the form
Just change your ajax call as below ... This also solves submitting with enter issue.
$('#mail').submit( function() {
var mail = $("#mail_content").val();
alert(mail);
$.ajax({
type: "POST",
url: "process.php",
data: "mail="+ mail,
success: function(){
alert("success");
}
});
return false;
});
first thing I see is, your .button
is a submit input, so when you click it, the form will be submitted, instead of the ajax call.
Make it a button
<input type="button" name="submit" class="button" id="submit_btn" value="SAVE" />