Ajax submission Form, and can support file upload

Source: Internet
Author: User

when we submit the form but do not want to refresh the page, we can consider using AJAX to implement the submission function, but there is a limitation is when the file upload is not feasible, the following with the help of jquery.form can be very convenient to meet our needs. 1. Forms:<form class= "UI form Error-page" id= "Error_page" method= "POST" action= "{{URL (' Web/save/error-page ')}}" Enctype = "Multipart/form-data" ><input type= "text" Name= "upload_item_key[0]" placeholder= "error code" ><input type= "file" Name= "upload_item_value[0]" style= "display:none;" ><input type= "text" Name= "upload_item_key[1]" placeholder= "error code" ><input type= "file" Name= "upload_item_value[1]" style= "display:none;" ><input type= "text" Name= "upload_item_key[2]" placeholder= "error code" ><input type= "file" Name= "upload_item_value[2]" style= "display:none;" ></form><div class= "UI green Button Save" > Save </div> 2.ajax notation (with the help of Jquery.form):$ (document). Ready (function () {var options = {success:function (data) {//After successful operation}}; $ (". Save"). Click (function () {$ ("#error_page"). Ajaxsubmit (options);});}); 3. Background reception (using the Laravel framework) $request->input (' Upload_item_key ') //file is empty and not empty when it is not possible to use an array to receive, because the need for key and value to correspond, so receive each, because upload_item_value[x] has a suffix, the order will not be messy, recommend to try it yourself$request->input (' Upload_item_valuey ')//When a file is empty$request->file (' upload_item_value ')//Receive file non-empty entries   Of course do not forget to introduce plugins,Jquery.form official website: http://plugins.jquery.com/form/

Ajax submission Form, and can support file upload

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.