This article mainly introduces the example explanation of AjaxSubmit() to submit file files. It is very good and has reference value. Friends who need it can refer to it.
I have checked various methods on the Internet before, and I want to Submit the file file and be able to receive the return value. It is recommended to use the ajaxSubmit() method.
Most of the recommendations on the Internet are like this:
$("#formId").submit( $(this).ajaxSubmit({ url:..., type:..., success:function(){ ... } }); return false;//阻止自动提交 );
But when you use it, you will find that there will be multiple submissions. Request once for the first time, twice for the second time….
And ajaxSubmit() itself has the submit() function, so there is no need to do this, just use:
var opt = { type:'post', datatype:'json', url:'../../../rybmanagement/upLoadFile', success: function(data) { ... } }; $("#formId").ajaxSubmit(opt);//相当于from.submit()
Introduce the file:
<script src="jquery-form.js" type="text/javascript"></script> <script src="../../js/jquery-2.1.1.min.js"></script>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
AjaxFileUpload Struts2 implements multi-file upload function
##Implements ajax sending asynchronous requests (graphic tutorial)
Ajax implementation of uploading images, saving them to the background and reading them (graphic tutorial)
The above is the detailed content of AjaxSubmit() submits the file file. For more information, please follow other related articles on the PHP Chinese website!