1

このプラグインを使用して、asp.netmvc3のAjaxを介したファイルのアップロードを行いました。 http://malsup.com/jquery/form/#ajaxSubmit ただし、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

1 に答える 1

4

IE 7は古いブラウザであり、XMLHttpRequestレベル2をサポートしていません。

古いブラウザの場合、XMLHttpRequestオブジェクトのレベル1の実装を使用してファイルをアップロードすることはできないため、iframeを含むフォールバックテクノロジが使用されます。これは一般的なフォールバック手法ですが、固有の制限があります。iframe要素は、フォームの送信操作のターゲットとして使用されます。これは、サーバーの応答がiframeに書き込まれることを意味します。これは、応答タイプがHTMLまたはXMLの場合は問題ありませんが、応答タイプがスクリプトまたはJSONの場合は同様に機能しません。どちらにも、HTMLマークアップで見つかった場合にエンティティ参照を使用して表現する必要のある文字が含まれていることがよくあります。

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

于 2012-04-24T12:12:36.210 に答える