我有一个可在Chrome和Firefox中使用的查询表单,但提交按钮并不想在IE中工作。 它允许我在文本框中输入任何信息,其余的功能似乎很好,它只是提交按钮,不会给我回电。
这是 fiddle
<div class="form">
<form id="form" action="" method="post">
<div class="div_input">
<input type="text" name="c_name" value="Name" onfocus="if(this.value=='Name')this.value=''" onblur="if(this.value=='')this.value='Name';" />
</div>
<div class="div_input">
<input type="text" name="c_email" value="E-mail" onfocus="if(this.value=='E-mail')this.value=''" onblur="if(this.value=='')this.value='E-mail';" />
</div>
<div class="div_input">
<input type="text" name="c_tel" value="Telephone" onfocus="if(this.value=='Telephone')this.value=''" onblur="if(this.value=='')this.value='Telephone';" />
</div>
<div class="div_textarea">
<textarea name="c_text" rows="1" cols="1" onfocus="if(this.value=='Text')this.value=''" onblur="if(this.value=='')this.value='Text';">Text</textarea>
</div>
<div class="div_btn">
<input id="submit" type="submit" name="c_send" value="" />
</div>
<div class="div_warnings"></div>
<div class="loading">
<img src="" alt="Loading" />
</div>
<div class="alert">
<img src="" alt="Loading" />
</div>
<div class="clear"></div>
</form>
</div>
<? php
/*
* Ajax form submit
*/
#request sent using HTTP_X_REQUESTED_WITH
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
if (isset($_POST['c_name']) AND isset($_POST['c_email']) AND isset($_POST['c_tel']) AND isset($_POST['c_text'])) {
$to = 'coryjharris1@gmail.com';
$name = filter_var($_POST['c_name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['c_email'], FILTER_SANITIZE_EMAIL);
$telephone = filter_var($_POST['c_tel'], FILTER_SANITIZE_STRING);
$message = filter_var($_POST['c_text'], FILTER_SANITIZE_STRING);
$sent = email($to, $email, $name, $telephone, $message);
if ($sent) {
echo 'Message Sent!';
}
} else {
echo 'All Fields are required';
}
return;
}
/**
* email function
*
* @return bool | void
**/
function email($to, $from_mail, $from_name, $subject, $message) {
$header = array();
$header[] = "MIME-Version: 1.0";
$header[] = "From: {$from_name}<{$from_mail}>";
/* Set message content type HTML*/
$header[] = "Content-type:text/html; charset=iso-8859-1";
$header[] = "Content-Transfer-Encoding: 7bit";
if (mail($to, $subject, $message, implode("\r\n", $header))) return true;
}
?><script>
$(document).ready(function () {
var form = $('#form'); // contact form
var submit = $('#submit'); // submit button
var alert = $('.alert'); // alert div for show alert message
// form submit event
form.on('submit', function (e) {
e.preventDefault(); // prevent default form submit
// sending ajax request through jQuery
$.ajax({
url: '', // form action url
type: 'POST', // form submit method get/post
dataType: 'html', // request type html/json/xml
data: form.serialize(), // serialize form data
beforeSend: function () {
alert.fadeOut();
submit.html('Sending....'); // change submit button text
},
success: function (data) {
alert.html(data).fadeIn(); // fade in response data
form.trigger('reset'); // reset form
submit.html('Send Email'); // reset submit button text
},
error: function (e) {
console.log(e)
}
});
});
});
答案 0 :(得分:0)
删除console.log(e),IE无法识别
console.log(e)