Nonsense is not much to say, the key code looks like this:
<script> $ ('. Screenshot_input '). Change (function () {//Get the file object that is equivalent to the $_files data var domfile = $ (this) that can be directly post [0].F
Iles[0] var domform = $ (' #testForm ') [0]//The form object is directly taken as the parameter new FormData object var formData = new FormData (domform);
Append file Object formdata.append (' file ', domfile); $.ajax ({url: ' {{path (' Acme_admin_app_dealappscreenshot ')}} ', type: ' POST ', Data:formdata, processdata:false,//t Ell jquery not to process the data contenttype:false,//Tell jquery isn't to set ContentType xhr:function () {//This is the key to getting the original
Raw XHR objects do all the things previously done var xhr = jQuery.ajaxSettings.xhr (); Xhr.upload.onload = function () {alert (' Finish downloading ')} xhr.upload.onprogress = function (EV) {if (ev.lengthcom
putable) {var percent = * ev.loaded/ev.total;
Console.log (Percent,ev)} return XHR;
}, Success:function (data) {alert (data)}}) </script> Array ([name] => cooff [email] => Qq.comaa Array ([file] => array ([name] => yunce2.0 test. apk [Type] =&Gt application/vnd.android.package-archive [Tmp_name] =>/tmp/php4jxt0c [ERROR] => 0 [size] => 6476627)
It is convenient to send form forms and file objects to the PHP back-end controller at once.
The above is a small set of jquery to introduce the use of $.ajax when the original XMLHttpRequest object, 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!