admin管理员组

文章数量:1406951

here is the input file:

 <input type="file" class="form-control" id="tab3_fileAddproof" name="tab3_fileAddproof" autoplete="off">

here is the javascript:

 $("#tab3_fileAddproof", r).change(function (e) {
                debugger
                var formData = new FormData();                   

                var file = document.getElementById(e.id).files[0];
                formData.append("FileUpload", file);

the error is on var file.

here is the input file:

 <input type="file" class="form-control" id="tab3_fileAddproof" name="tab3_fileAddproof" autoplete="off">

here is the javascript:

 $("#tab3_fileAddproof", r).change(function (e) {
                debugger
                var formData = new FormData();                   

                var file = document.getElementById(e.id).files[0];
                formData.append("FileUpload", file);

the error is on var file.

Share Improve this question asked May 6, 2017 at 10:16 ManojManoj 111 gold badge1 silver badge3 bronze badges 6
  • Simple: the id of the event (e.id) has nothing to do with the id of the element. – Hugues M. Commented May 6, 2017 at 10:21
  • where should i change – Manoj Commented May 6, 2017 at 10:22
  • on file change here i save the file by using ajax and javascript – Manoj Commented May 6, 2017 at 10:23
  • How do i find the file name and details of the file usaing javascript – Manoj Commented May 6, 2017 at 10:24
  • (sorry, removed ment that was too much of a rant (and wrong)). Please still clean up a bit: what is this debugger statement in the middle of your code? – Hugues M. Commented May 6, 2017 at 10:31
 |  Show 1 more ment

1 Answer 1

Reset to default 3

The event object has a target property that is the element that caused it to fire.

var clicked = e.target;
var file = clicked.files[0];

There are a few ways the above can fail - if the changed element is not a file input and if it is empty.

本文标签: javascriptUncaught TypeError Cannot read property 39files39 of nullStack Overflow