当前位置:Gxlcms > PHP教程 > AJAX无刷新上传图片_PHP教程

AJAX无刷新上传图片_PHP教程

时间:2021-07-01 10:21:17 帮助过:63人阅读

目录结构如下:

其中files文件夹中存放上传来的图片。

index.html代码如下:














jquery.form.js代码如下:


"use strict"


 feature == $("").get(0).files !=== window.FormData !=== 

    
     (!'ajaxSubmit: skipping submit process - no element selected'  method, action, url, $form =  ( options == 'function'== .attr('method'= .attr('action'= ( action === 'string') ? $.trim(action) : ''= url || window.location.href || ''
        url = (url.match(/^([^#]+)/)||[])[1= $.extend(|| 'GET'/^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
    
     veto =.trigger('form-pre-serialize', ['ajaxSubmit: submit vetoed via form-pre-serialize trigger' 
     (options.beforeSerialize && options.beforeSerialize(, options) === 'ajaxSubmit: submit aborted via beforeSerialize callback'  traditional = ( traditional ==== elements = qx, a = ==
     (options.beforeSubmit && options.beforeSubmit(a, , options) === 'ajaxSubmit: submit aborted via beforeSubmit callback' 
    .trigger('form-submit-validate', [a, 'ajaxSubmit: submit vetoed via form-submit-validate trigger'  q == ( q ? (q + '&' + (options.type.toUpperCase() == 'GET'+= (options.url.indexOf('?') >= 0 ? '&' : '?') += ;  
= q; 
 callbacks =
     (!options.dataType && oldSuccess = options.success ||  fn = options.replaceTarget ? 'replaceWith' : 'html' = (data, status, xhr) { 
         context = options.context ||  ;    
         ( i=0, max=callbacks.length; i < max; i++||
     fileInputs = $('input:file:enabled[value]', ); 
     hasFileInputs = fileInputs.length > 0 mp = 'multipart/form-data' multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == fileAPI = feature.fileapi &&"fileAPI :" + shouldUseFrame = (hasFileInputs || multipart) && !
    
     (options.iframe !==  && (options.iframe ||
        
          ((hasFileInputs || multipart) &&
     ( k=0; k < elements.length; k++= 
    .trigger('form-submit-notify', [ 
     serialized = $.param(extraData).split('&' len = result = (i=0; i < len; i++= serialized[i].split('='0])] = decodeURIComponent(part[1
     formdata =  ( i=0; i < a.length; i++ serializedData = ( p =  s = $.extend('POST'
            s.xhr =  xhr ==  percent = 0 position = event.loaded || event.position; 
                         total == Math.ceil(position / total * 100=  beforeSend == =
     form = $form[0 useProp = !! ($(':input[name=submit],:input[id=submit]'
            
            alert('Error: Form elements must not have name or id of "submit".'
             (i=0; i < elements.length; i++='disabled', 'disabled'= $.extend(= s.context ||= 'jqFormIO' + (== $io.attr('name' (!'name'== $('