js ajax上传文件

  1. // js上传world
    var fileM=document.querySelector("#uploadFile");
    $("input[name=world]").change(function(){
    // console.log($("input[name=world]")[0].files);
    var formData = new FormData();
    // console.log($("#uploadFile")[0].files);
    var fileObj = fileM.files[0];
    formData.append('file',fileObj);
    // console.log(formData);
    $.ajax({
    url: "/admin/question/move_files.html",
    type: "POST",
    data: formData,
    dataType:"json",
    cache: false,
    contentType: false,
    processData: false,
    success: function(data) {
    console.log(data);
    if(data.status == 1){
    $("input[name=world_info]").val(data.info);
    }
    layer.msg(data.msg,{time:1500});
    },
    error: function(data) {
    layer.msg("网络错误",{time:1500});
    }

    })
    })
posted @ 2020-08-31 23:39  程序员小艺  阅读(1023)  评论(0编辑  收藏  举报