the form.submit () returns the data submission process

form.submit () sends a request is usually one-way, if you need to take the data returned, usually sends ajax request, but if it has an attachment in the form? (After a time to share with ajax function to upload attachments), really want to return data to know whether the function is successfully executed it? My solution is to add a target attribute in the form, add allowed to return data to a hidden iframe controls the returned data

 <label for="a"> 上传附件 </label>  
               <form id="uploadForm"  enctype="multipart/form-data" target="frameFile"  method="post">
             
                 <input type="file" id="a" name="a" onchange="fileUpload()" style="position:absolute;top:0px;right:0px;cursor:pointer; opacity:0;filter:alpha(opacity:0);z-index:999;"    />
                         
              </form>
                <name= 'Frame file'idiframe='frameFile' style="display:none">    
                </iframe>

The following is a return to the page in the background of the returned data processing

<script type="text/javascript">
    try {
        var data = eval("($result)")

        if (data.success) {
            alert(data.res)
        }
        window.top.LoadByFrame(data.success);
    } catch (e) {
        window.top.closeBg();

    }
</script>
function fileUpload()
    {
        var form = document.getElementById('uploadForm'); 
        form.action="XXX.do?";
        form.submit();
    }

This enables displaying the processed data in the hidden iframe 

Guess you like

Origin www.cnblogs.com/mingqi-420/p/10932188.html