About file upload non-Ajax submit get Background data problem _javascript tips

Source: Internet
Author: User
Tags file upload

below to introduce the file upload non-Ajax submitted to the background data operation method, the specific details are shown below;

<form name= "Configform" id= "Configform" "method=" Post "action=" "> ...
</form>

Get form data based on ID and then send AJAX request, get background return data, process data, perfect.

But if you need to upload files,

<tr>
<td class= "FontSize" > Please select File:</td>
<td><input type= "class=" Easyui-filebox "Id=" FileImport "name=" file "value=" "style=" width:300px; " ></td>
</tr>

This file data is not in the background, the form data This file is also null, you need

<form name= "Configform" id= "Configform" method= "POST" action= "" enctype= "Multipart/form-data" >

Add this enctype= "mutipart/form-data" background can be

@RequestMapping ("/saveappversion")
@ResponseBody public
modelmap saveappversion (String action, Tbdappversion tbdappversion,
@RequestParam (value = "file") Multipartfile file) {...
}

Receive.

However, the form submission request data must be required, Ajax is still not good (specific reasons can be Baidu. )

<form name= "Configform" id= "Configform" "method=" Post "action="/admin/systemconfig/saveappversion.do "enctype=" Multipart/form-data "> ...
</form>

Easyui inside the JS submit submitted

Handler:function () {
$ ("#configForm"). Submit ();

So the question is, how do I get back the background data after the submission?

<form name= "Configform" id= "Configform" method= "post" action= "/admin/systemconfig/saveappversion.do
" Enctype= "Multipart/form-data" target= "Myiframe" > .... </form>
<iframe name= "Myiframe" id= "If_json" style= "Display:none" >
</iframe>

Add a target to the form, which means that the data submitted for the successful return is written in the IFRAME named Myiframe, which refreshes the IFRAME and then gets the data.

Although Baidu is not a good bird, but some things can still be found, such as the following to obtain the method of IFRAME data!

Handler:function () {
$ ("#configForm"). Submit ();
$ ("#if_json"). Load (function () {//Get content in iframe
var body = $ (window.frames[' myiframe '].document.body);
var data = eval (' (' + body[0].textcontent + ') '); 
if (data.resultcode && data.resultcode!= 0) {
...
..        }else{.....
}}
);

The above is a small series to introduce the relevant file upload non-Ajax submitted to the background data, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.