Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

jquery post upload file


 $(document).ready(function() {
     $('#ProblemUpload').submit(function(e){
         e.preventDefault();
          $('#ProblemUpload').find('button').prop('disabled',true);
            var file_data = $('#fileData').prop('files')[0];   
            var form_data = new FormData();                  
            form_data.append('file', file_data);
            form_data.append('action', 'upload_sheet');
            $('#loaderWapper').slideDown();                         
            $.ajax({
                url: baseUrl+'apis/auth.php', // <-- point to server-side PHP script 
                dataType: 'text',  // <-- what to expect back from the PHP script, if anything
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,                         
                type: 'post',
                success: function(php_script_response){
                    let response = JSON.parse(php_script_response);
                    if(response.status == 'success'){
                        alertify.alert('Data inserted',response.msg );
                        $('#ProblemUpload').trigger('reset');
                    }else{
                        alertify.error(response.msg)
                    }
                    $('#loaderWapper').slideUp();    
                    $('#ProblemUpload').find('button').prop('disabled',false);
                }
            });
     })
 })
 
PREVIOUS NEXT
Tagged: #jquery #post #upload #file
ADD COMMENT
Topic
Name
2+5 =