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

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();
    
    评论

报告相同问题?