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