zoukankan      html  css  js  c++  java
  • ajax+jquery上传图片

    利用ajax进行图片上传,啥也不说了,上代码~

    <input type="file" id="uploadImg">

    <span  onclick='upload()'>更换</span>

     

    function upload(){
      if($('#uploadImg').val() == ''){  //检查input[type=file]是否有值
        // plus.nativeUI.toast('请选择图片再进行上传操作!');
        console.log('请选择图片再进行上传操作!');
      }else{
        var formdata=new FormData($("#uploadImg"));
        formdata.append('formFile',$("#uploadImg").get(0).files[0]);
      $.ajax({
        url: 'https://hdj.microsun.tech/api/Users/UpFile/394c65ab-1cb0-4f8c-941d-08d7754da439/avatar',
        data: formdata,
        type: "POST",
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function(data) {
        console.log(JSON.stringify(data));
        $('#updata_img').src
        },
        error: function(data) {
        console.log(data.status);
        }
      });
     }
    }

  • 相关阅读:
    AngularJS
    Java
    Java
    AngularJS
    Java
    Java
    AngularJS
    Java
    Debian
    Java
  • 原文地址:https://www.cnblogs.com/flowerM/p/11966503.html
Copyright © 2011-2022 走看看