开发者

jQuery Uploads a file, and then submits the form normally

I hope that I can make sense of this question.

I currently am using jQuery Form Plugin + Validation which works great.

But what I am trying to accomplish is,

1, Upload a temp-file for manipulating in the next step

2, Once file has been uploaded, submit the form normally to go to the next step (a new file).

So i'm just a 100% sure how to accomplish that, I currently use this code.

$("#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.开发者_高级运维");  
                }
            });
        }
    });

And for my Form

<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>


Simple answer: You can't upload files through AJAX. You'll have to submit the form to another page and then go from there.

More: Technically you can, but not like this. It involves creating an iframe and submitting the files through that. Either way, you have to have a post back, you can't use the XMLHttpRequest object.

If you do a quick google search, you can find plug-ins that do this for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜