1

我希望我能理解这个问题。

我目前正在使用 jQuery Form Plugin + Validation 效果很好。

但我想要完成的是,

1、上传一个临时文件用于下一步操作

2、文件上传完毕后,正常提交表单进入下一步(新建文件)。

所以我只是 100% 确定如何做到这一点,我目前使用这段代码。

$("#fileUpload").validate({
        submitHandler: function(form) {

            $(form).ajaxSubmit({
                beforeSubmit: function() {
                    $('input').attr("disabled", true);
                    $("#uploadResponse").show('slow');
                    $('#uploadResponse').append("<img src='images/icons/ajax-loader.gif' />");
                },
                success: function(responseText, statusText, xhr, form) {
                    $('input[type=submit]').attr("disabled", false);
                    $('input[type=file]').attr("disabled", true);
                }, 
                error: function (responseText, statusText, xhr, form) {
                    alert("Oops... Looks like there has been a problem.");  
                }
            });
        }
    });

对于我的表格

<div id="uploadResponse" style="display: none;"> File Uploading, this can take a few minutes... </div>

<form action='page.ImportContacts2.php' name="mergeCSV"  id="fileUpload" method="post" enctype="multipart/form-data" >
        File: <input id="getCSV" name="getCSV" class="required" type="file">

        Delimiter Type: 
        <select id="delimiter" name="delimiter">
            <option value="1" selected="selected">Comma</option>
            <option value="2">Tab</option>
        </select>

        Enclosure Type: 
        <select id="enclosure" name="enclosure">
            <option value="1" selected="selected">Double Quotes (")</option>
            <option value="2">Single Quotes (\')</option>
        </select>

        <button type="submit" name="SubmitCSV" id="SubmitCSV" value="SubmitCSV" class="csvCol3Button buttonSmall">Upload File</button>

</form>
4

1 回答 1

1

简单的回答:您不能通过 AJAX 上传文件。您必须将表单提交到另一个页面,然后从那里开始。

更多:从技术上讲你可以,但不是这样。它涉及创建一个 iframe 并通过它提交文件。无论哪种方式,您都必须回发,您不能使用 XMLHttpRequest 对象。

如果您进行快速 google 搜索,您可以找到为您执行此操作的插件。

于 2010-12-02T00:30:12.657 回答