我有一個表格和一段javascript
代碼來創建AJAX
表單。奇怪的是,當我在Internet Explorer中提交表單時,唯一顯示的是[object Object]
。該表單在Google Chrome中運行良好。這裏是我的代碼:無法取消對Ajax表單的默認操作提交
表頭:
<form id="page-details-form" class="ajax-form" name="page-details-form" method="POST" action="/pages/save/1">
的Javascript監聽器:
<script>
$(function(){
$(document).on("submit",".ajax-form",function(e){
if (window.event) {
window.event.returnValue = false;
}
e.preventDefault ? e.preventDefault() : e.returnValue = false;
$('.form-message').remove();
if($('#onSubmitJsEval').html() && $('#onSubmitJsEval').html().length > 0)
{
eval($('#onSubmitJsEval').html());
}
var submitBtnValue = $('#submitBtn').html();
var formId = $(this).attr('id');
var postData = $(this).serializeArray();
$('#submitBtn') .html('<img src="images/ajax-loader.gif" />');
$('p.has-error') .remove();
$('div.has-error') .removeClass('has-error');
$.post($(this).attr('action'), postData, function(jsonResponse)
{
var jsonObject = jQuery.parseJSON(jsonResponse);
if(jsonObject.success == true)
{
$('<div class="<?=MESSAGE_SUCCESS_CLASS?>"><?=MESSAGE_SUCCESS_PREFIX?>'+jsonObject.message+'</div>').insertBefore("#" + formId + " h2");
if(jsonObject.insertedId > 0)
{
var stringPath = window.location.pathname.substr(window.location.pathname.length - 1);
document.location.href = window.location.pathname + ((stringPath != "/") ? "/" : "") + jsonObject.insertedId;
}
}
else
{
$('<div class="<?=MESSAGE_ERROR_CLASS?>"><?=MESSAGE_ERROR_PREFIX?>'+jsonObject.message+'</div>').insertBefore("#" + formId + " h2");
$.each(jsonObject.errors, function(index, value){
$('[name='+index+']').parent().addClass('has-error');
$('[name='+index+']').after('<p class="has-error help-block">'+value+'</p>');
})
}
$('#submitBtn').html(submitBtnValue);
});
});
});
</script>
我想除了當前選項的幾個選項:
if (e.preventDefault) e.preventDefault();
e.returnValue = false
e.returnValue = false
e.preventDefault
後有沒有人有一個想法?如果我需要發佈更多的代碼,請讓我知道。如果你願意,我可以發佈所有的代碼。
非常感謝!
'e.returnValue = false ;;'double semicons???爲什麼不試試'e.preventDefault();'?爲什麼你需要這樣的條件? – Jai
查看更新...... –
對不起,我剛剛貼錯了代碼。我更新它知道完整的JavaScript代碼。 –