zl程序教程

您现在的位置是:首页 >  前端

当前栏目

JAVASCRIPT使用ajax做异步上传文件详解编程语言

2023-06-13 09:20:43 时间

JAVASCRIPT使用ajax做异步上传文件,很流行的上传方式:代码如下

首先是HTML文档:

!DOCTYPE html

html

head

    meta name= viewport content= width=device-width /

    script src= ~/scripts/jquery-1.8.2.min.js /script

    title Index /title

    script

        $(function() {

            $( :button ).click(function () {

                var formData = new FormData();

                var file = $( input[type= file ] )[0].files[0];

                formData.append( files , file);

                $.ajax({

                    url: /Upload/Upload ,  //server script to process data

                    type: POST ,

                    //ajax事件处理

                    //beforeSend: beforeSendHandler,

                    //success: completeHandler,

                    //error: errorHandler,

                    // Form数据

                    data: formData,

                    cache: false,

                    contentType: false,

                    processData: false

                });

            });

        });

    /script

/head

body

    form enctype= multipart/form-data

        input name= file type= file multiple= multiple /

        input type= button value= Upload /

        input type= text name= userName value= ice /

    /form

     

/body

/html

JAVASCRIPT使用ajax做异步上传文件详解编程语言

转载请注明来源网站:blog.ytso.com谢谢!

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/15056.html

cjava