這是我的測試用例。如果發佈表單,則發送500錯誤響應。如果不是,則發送表單。使用jQuery表單插件通過Ajax上傳文件時不會調用錯誤處理程序
如果文件輸入標記被註釋掉,則調用錯誤處理程序。如果文件輸入標籤存在,則不調用錯誤處理程序。我認爲這可能與jQuery需要使用iframe來處理上傳和iframe的事實有關。don't seem to respond to the error handler。
編輯: 如果我添加iframe: true
傳遞給ajaxSubmit
強制使用一個iframe的選擇,非文件上傳的情況下停止工作也,所以它肯定具有與iframe來辦。我正在使用jQuery Form Plugin。
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
header('HTTP/1.1 500 Internal Server Error');
die;
} else {?>
<html><head>
<script type='text/javascript'
src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=2.9.2'></script>
<script type='text/javascript'
src='http://github.com/malsup/form/raw/master/jquery.form.js?v2.43'></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('a').click(function() {jQuery('form').ajaxSubmit({error: function(){alert('error handler called');}})});
});
</script>
</head><body>
<form method="POST">
<input type="text" name="mytext" />
<input type="file" name="myfile" /><!-- comment this element out -->
<input type="hidden" name="blah" value="blah" />
<a>submit</a>
</form>
</body></html>
<?php }
有沒有什麼辦法讓錯誤處理程序在這兩種情況下被調用?
「ajaxSubmit」究竟是什麼?這是一個插件什麼的?你自己的代碼?它不在jQuery 1.4.2中。 – Pointy 2010-05-13 13:45:18
對不起,我應該包含一個鏈接到問題標題中提到的插件:http://jquery.malsup。com/form/ – 2010-05-13 13:54:37