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
1 Answer
Reset to default 3The 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
版权声明:本文标题:javascript - Uncaught TypeError: Cannot read property 'files' of null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745051159a2639661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论