darkedeneurope.com : Getting StartedUsing darkedeneurope.comUsing darkedeneurope.com PluginsUsing darkedeneurope.com UIDeveloping darkedeneurope.com CoreDeveloping darkedeneurope.com PluginsDeveloping darkedeneurope.com UIQUnit và TestingAbout the darkedeneurope.com darkedeneurope.comdarkedeneurope.com Conferencesdarkedeneurope.com MobileDeveloping darkedeneurope.com Mobile

Bạn đang xem: How to upload files asynchronously using jquery?

Xem thêm: Tt In Advance Là Gì - Phân Biệt Tt Và Ttr Trong Khai Báo Hải Quan 2021
Hello again,I am trying to lớn create a possibility for users to lớn 1) select an image using an input field --> the image is displayed in a preview box by the function readURL --> that works fine2) upload that image to process máy chủ side wise by clicking a div calling a function uploadImage --> HERE IS THE PROBLEMThe html code:No tag around used. Also functions are called on events --> both function give at least a response when I for examploe trouble shooting using alert();
$( '#imgInput' ).change( readURL ); $( 'div#submitAddImage' ).on( 'click' , uploadImage ); With the readURL function I am creating an object using FileReader mechanism. The tệp tin is then displayed in $( 'img#previewWindow' ).var myFile = ''; function readURL( e ) if ( this.files && this.files<0> ) var reader = new FileReader(); reader.onload = ( function( e ) $( 'img#previewWindow' ).attr( 'src' , e.target.result ); ); reader.readAsDataURL( this.files<0> ); myFile = this.files<0>; // store file in global variable Clicking the div-Button executes the upload funtion.function uploadImage() var data = new FormData(); $.each( myFile , function( key , value ) data.append( key , value ); ); $.ajax( url: 'changeUploadImage.php', type: 'POST', data: data, cache: false, dataType: 'json', processData: false, contentType: false, success: function( data , textStatus , jqXHR ) if( typeof data.error === 'undefined' ) submitForm( event, data ); else alert( 'ERRORS: ' + data.error ); , error: function(jqXHR, textStatus, errorThrown) alert( 'error on upload' ); ); THE RESULT IS THAT I over UP WITH THE ALERT 'error on upload'. So the upload fails. I don't understand also after long trying how to create an object (don't know for example how to show me the object, what are to lớn properties lượt thích path, type, image itself,...) và then lớn pass over to lớn the ajax function lớn uplaod. I also vì chưng not understand, whether I need the each function for the maFile variable. I thought I have profund skills using darkedeneurope.com, but connot master this issue, which sucks!So what is it exactly that creates me the object và how can I pass on to another function?Can someone help? I am thinking already about trying other approached discarting the ajax upload function. But that would be even more frustrating...Thank you in advanceFrank