0
我在IE8上收到'對象不支持此方法或屬性'的錯誤。代碼它指的是該行低於:IE8上的jQuery驗證錯誤
$('#example-advanced-form').ajaxForm({
target: '.success',
success: function() {
$('.success').fadeIn('fast');
$("#contact_form").toggle("fast");
}
});
我使用這個的原因是FormData
不低於IE10工作。
以下是錯誤的截圖:
以下是完整的腳本...
<script type="text/javascript">
var form = $("#example-advanced-form").show();
$('#role').validate({ // initialize the plugin
rules: {
role: {
required: true,
}
}
});
form.steps({
headerTag: "h3",
bodyTag: "fieldset",
transitionEffect: "slideLeft",
onStepChanging: function (event, currentIndex, newIndex)
{
// Allways allow previous action even if the current form is not valid!
if (currentIndex > newIndex)
{
return true;
}
// Needed in some cases if the user went back (clean up)
if (currentIndex < newIndex)
{
// To remove error styles
form.find(".body:eq(" + newIndex + ") label.error").remove();
form.find(".body:eq(" + newIndex + ") .error").removeClass("error");
}
form.validate().settings.ignore = ":disabled,:hidden";
return form.valid();
},
onStepChanged: function (event, currentIndex, priorIndex)
{
//
if (currentIndex === 2 && $("input:radio[name='workfor']").is(":checked"))
{
form.steps("next");
}
},
onFinishing: function (event, currentIndex)
{
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinished: function (event, currentIndex)
{
if(navigator.appVersion.indexOf("MSIE 8.")!=-1 || navigator.appVersion.indexOf("MSIE 9.")!=-1) {
//alert("old IE!");
// bind 'myForm' and provide a simple callback function
$('#example-advanced-form').ajaxForm({
target: '.success',
success: function() {
$('.success').fadeIn('fast');
$("#contact_form").toggle("fast");
}
});
} else {
//alert("Not old IE!");
//data to be sent to server
var m_data = new FormData();
m_data.append('name', $('input[name=name]').val());
m_data.append('number', $('input[name=number]').val());
m_data.append('email', $('input[name=email]').val());
m_data.append('workfor', $('input[name=workfor]:checked').val());
m_data.append('role', $('select[name=role]').val());
m_data.append('cv', $('input[name=cv]')[0].files[0]);
m_data.append('coverletter', $('textarea#coverletter').val());
//instead of $.post() we are using $.ajax()
//that's because $.ajax() has more options and flexibly.
$.ajax({
url: 'contact_me.php',
data: m_data,
processData: false,
contentType: false,
type: 'POST',
dataType:'json',
success: function(response){
//load json data from server and output message
if(response.type == 'error'){ //load json data from server and output message
output = '<div class="error">'+response.text+'</div>';
}else{
output = '<div class="success">'+response.text+'</div>';
$("#contact_form").toggle("fast");
}
$(".form_message").hide().html(output).slideDown();
}
});
}//END browser check coniditonal statement
}
}).validate();
</script>
我剛剛發佈了完整的腳本 – Amesey 2014-10-10 12:01:23
好的,但我不能看這個腳本並確定問題;你必須使用一個調試工具來查看出現了什麼錯誤...... JS錯誤很難調試,而且只是通過目測來調試它們是非常困難的。 – 2014-10-10 12:05:24
而不是試圖使用ajaxForm是否有另一種方式,我可以使用jQuery使表單發送到不同的發送郵件PHP文件? 這篇文章說ajax表單在ie 8中不起作用,但它在9中也不起作用。http://stackoverflow.com/questions/12163558/ajax-form-does-not-work-with- internet-explorer-8-9 – Amesey 2014-10-10 13:15:25