zoukankan      html  css  js  c++  java
  • FormData异步上传

    1.代码片段一:

     ajaxUpload: function () {
          var url = this.$avatarForm.attr('action'),
              data = new FormData(this.$avatarForm[0]),
              _this = this;
    
          $.ajax(url, {
            type: 'post',
            data: data,
            dataType: 'json',
            processData: false,
            contentType: false,
    
            beforeSend: function () {
              _this.submitStart();
            },
    
            success: function (data) {
              _this.submitDone(data);
            },
    
            error: function (XMLHttpRequest, textStatus, errorThrown) {
              _this.submitFail(textStatus || errorThrown);
            },
    
            complete: function () {
              _this.submitEnd();
            }
          });
        },

    2.代码片段二:

    $(document).ready(function (e) {
        $("#uploadForm").on('submit',(function(e) {
            e.preventDefault();
            $.ajax({
                url: "upload.php",
                type: "POST",
                data:  new FormData(this),
                contentType: false,
                cache: false,
                processData:false,
                success: function(data)
                {
                $("#targetLayer").html(data);
                },
                error: function() 
                {
                }           
           });
        }));
    });
  • 相关阅读:
    Go--指针
    Go--struct
    Go--函数
    Go基础
    流程控制
    Go前言
    变量与常量
    Django(三):HttpRequest和HttpResponse
    Django(二):url和views
    tensorflow(一):图片处理
  • 原文地址:https://www.cnblogs.com/wuheng1991/p/6650184.html
Copyright © 2011-2022 走看看