0

私はこのHTMLを持っています:

<script type="text/javascript">
                        function uploadDone(response) {
                                alert(response);
                            }
                            function init() {
                                        document.getElementById('file_upload_form').onsubmit=function() {
                                            document.getElementById('file_upload_form').target = 'upload_target'; //'upload_target' is the name of the iframe
                                            document.getElementById("upload_target").onload = uploadDone(response);
                                        }
                                    }
                        </script>
                        <form method="get" id="file_upload_form" enctype="multipart/form-data" action="../includes/parsecsv.ajax.php" target="upload_target">
                            <label class="uploadClick">
                                <button class="normal">Click to Upload Sign Ups CSV</button>
                                <input type="file" id="uploadSignups file" name="file">
                            </label>
                            <span class="uploadDrag"><span>or</span>Drag Your Sign Ups CSV Here</span>
                            <button type="submit" name="action">hello</button>
                            <iframe id="upload_target" name="upload_target" src="" style="width:0px; height:0px; border:none;"></iframe>
                        </form>

送信ボタンをクリックすると、ファイル入力で選択したファイルが ajaxically を介してアップロードされるはずです<iframe>。アップロードはできたようですがuploadDone()、アップロードが完了しても動かないのですか?何が問題なのですか?

4

3 に答える 3

0

ここでは、応答を持つJSPファイルを作成し、JSPでスクリプトを記述して、uploadDoneすでにドキュメントにロードされているメソッドにアクセスする必要があります。

JSPのスクリプトは次のようになります。

 parent.document.uploadDone(response);
于 2011-11-26T07:15:57.927 に答える
0

iFrame のウィンドウ要素にイベントを追加するだけだと思います。

document.getElementById("upload_target").contentWindow.onload = function(response) { uploadDone(response) };

uploadDoneまた、関数内にラップしていることにも注意してください。それ以外の場合は、それを呼び出して、それが返すものとしてイベントを設定します。

于 2011-11-26T05:28:02.720 に答える
0

javascriptから親Iframeにアクセスする方法、IFrameのparentプロパティを使用する

于 2011-11-26T05:31:11.177 に答える