1

我在asp.net mvc3中使用這個插件通過Ajax進行文件上傳。 http://malsup.com/jquery/form/#ajaxSubmit 但它不會在IE7中工作。Ajax文件上傳在IE7中不起作用

$("#Controls").submit(function() { 
      var options = { 
       url: "/Education/upDoc", 
       datatype: "json", 
       success: showResponse 
      }; 
    $(this).ajaxSubmit(options); 
}); 

function showResponse(responseText, statusText, xhr, $form) { 
     alert("sr"); 
     alert("Sr " + responseText.success); 
     if (responseText.success == true) { 
      //some code 
     } 
    } 

<form action='' id='Controls' method='post' enctype='multipart/form-data'> 
<table> 
         <tr> 
         <td>File Type</td> 
         <td><span class='leftten'></span></td> 
         <td> 
         @*<select id='documentType' name='documentType'> 

         </select> *@ 
         @Html.DropDownList("documentType", doctypelist, new { @id = "documentType" }) 
         </td> 

         <td><img src='../../img/AlertSign.jpg' class='errImgDoc' data-style-tooltip='tooltip-shiny-red' title='' id='errFileType' height='18px' width='20px'/></td> 
         <td><span class='leftfortytwo'></span></td> 
         <td><input type='file' id='file' name='file' /></td> 
         <td><img src='../../img/AlertSign.jpg' class='errImgDoc' data-style-tooltip='tooltip-shiny-red' title='' id='errFile' height='18px' width='20px' /></td> 
         <td><span class='leftfortytwo'></span></td> 
         <td>Name</td> 
         <td><span class='leftten'></span></td> 
         <td><input type='text' id='description' name='description' /></td> 
         </tr> 
         </table> 
         <br /> 
         <div align='right'> 
         <table><tr> 
         <td><input type='button' id='eduUploadCancel' class='Cancel' onmouseover='CancelHover(this)' onmouseout='CancelMouseOut(this)' onclick='Cancel(this)' /></td><td><span class='leftten'></span></td><td><input type='submit' id='eduUploadSave' class='Save' onmouseover='SaveHover(this)' onmouseout='SaveMouseOut(this)' /></td></tr></table> 
         </div> 

</form> 

這裏,showResponse()永遠不會用IE7調用。在Chrome和Firefox上運行良好。請幫助!

回答

4

IE 7瀏覽器的老,不支持XMLHttpRequest級別2

對於舊的瀏覽器,回退技術被用於涉及 I幀,因爲它是不可能的使用水平上載文件的1 implmenentation XMLHttpRequest對象。這是常見的 後備技術,但它有固有的侷限性。 iframe 元素用作表單提交操作的目標,其中 表示將服務器響應寫入iframe。這是精 如果響應類型是HTML或XML,但如果 數據類型是script或JSON,這兩者往往含有 字符需要用實體引用來repesented時發現 不工作,以及在HTML標記中。

http://malsup.com/jquery/form/#file-upload

+0

所以,如果我的回答是純文本或XML,它會在IE瀏覽器? – 2012-04-24 12:13:44

+0

是的,我認爲,但如果你測試它應該會更好。 – 2012-04-24 16:43:15

+1

也許嘗試返回純文本JSON,然後使用JSON.parse() – ruffrey 2013-02-14 21:54:14