weixin_33727510 2016-05-27 17:35 采纳率: 0%
浏览 1255

FormData不是构造函数

I'm trying to make a ajax request to upload a image. My problem is when I create the FormData. My console is saying "dataForm is not a constructor".

How can I solve this ?

here is my script

$("#new-broadcast-image-static").on("change", function(formData) {
                var formData = new formData();

                // line that console point the error //
                var file = $("#new-broadcast-image-static")[0].files[0];
                formData.set("image", file);

                $.ajax({
                    url: apiUrl + "image/upload",
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false,
                    xhrFields: {
                        withCredentials: true
                    },
                    success: function(data) {
                        hashNewBroadcastImage = data.data.identifier;
                        $("#hash-new-broadcast-image-static").val(hashNewBroadcastImage);
                    }
                });
            });
  • 写回答

4条回答 默认 最新

  • weixin_33709219 2016-05-27 17:40
    关注

    Capitalize it: var formData = new FormData();

    But what are you trying to acomplish anyways? You are reasigning a variable you are getting as parameter:

     $("#new-broadcast-image-static").on("change", function(formData) {
          var formData = new formData();
    

    You probably want to change it to something like

     $("#new-broadcast-image-static").on("change", function(e) {
          var formData = new FormData();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。