admin管理员组文章数量:1406177
I ran this code through Chrome and Firefox and it works well. Whenever I run it through Internet Explorer for testing purposes it will not work. I checked the javascript consule and I'm getting: SCRIPT5007: Unable to get value of the property '0': object is null or undefined. Can someone please tell me why this is ing up and what I can do to fix it?
$('#audiofile1').bind('change', function () {
if (this.files[0].type != 'image/png') {
$('#audiofile1').each(function () {
$(this).after($(this).clone(true)).remove();
});
alert(this.files[0].name + ' is not a valid file type.');
} else {
if (this.files[0].size > '5000') {
$('#audiofile1').each(function () {
$(this).after($(this).clone(true)).remove();
});
var size = this.files[0].size;
var maxSize = 100;
var exceedingSize = size - maxSize;
alert(this.files[0].name + ' exceeds the maximum file size');
} else {
$("#audiofile1").fadeTo(1500, 0.20);
alert(this.files[0].name + ' was added successfully.');
}
}
});
I ran this code through Chrome and Firefox and it works well. Whenever I run it through Internet Explorer for testing purposes it will not work. I checked the javascript consule and I'm getting: SCRIPT5007: Unable to get value of the property '0': object is null or undefined. Can someone please tell me why this is ing up and what I can do to fix it?
$('#audiofile1').bind('change', function () {
if (this.files[0].type != 'image/png') {
$('#audiofile1').each(function () {
$(this).after($(this).clone(true)).remove();
});
alert(this.files[0].name + ' is not a valid file type.');
} else {
if (this.files[0].size > '5000') {
$('#audiofile1').each(function () {
$(this).after($(this).clone(true)).remove();
});
var size = this.files[0].size;
var maxSize = 100;
var exceedingSize = size - maxSize;
alert(this.files[0].name + ' exceeds the maximum file size');
} else {
$("#audiofile1").fadeTo(1500, 0.20);
alert(this.files[0].name + ' was added successfully.');
}
}
});
Share
Improve this question
edited Jan 19, 2013 at 7:59
Ilmari Karonen
50.4k9 gold badges95 silver badges156 bronze badges
asked Jan 19, 2013 at 7:33
user1661548user1661548
1
- of your actual JSON object "this" u can post example? If it has trailing mas thats your problem – sajawikio Commented Jan 19, 2013 at 7:41
3 Answers
Reset to default 2if (this.files[0].type != 'image/png') {
Inside your event handler, jQuery makes this
the DOM element for which the handler was registered. Either that element does not have a defined files
property, or that property's value is null
or undefined
.
This is because Internet Explorer 9 and below do not support the File API. You should probably just skip binding the handler if the File API is not available:
if ($('#audiofile1')[0].files) {
$('#audiofile1').bind('change', function () {
// ...
});
}
Apparently, IE only supports the HTML5 File API starting with version 10. Thus, in IE 9, there is no .files
property to access at all.
Unfortunately, I don't know any way to work around this, except to tell your users to upgrade and/or to provide some alternative (likely server-side) method for users on older browsers to acplish whatever it is you're doing. In your case, assuming that you're eventually uploading the files to the server for further processing anyway, you could just skip the client-side checks on browsers that don't support them, and simply tell your users what kind of files will be accepted.
I am getting this (same/similar) error when attempting to Open a Jquery UI Dialog :
SCRIPT5007: Unable to get value of the property '_focusTabbable': object is null or undefined.
The change that I made that appears to have caused this error...:
a) Change to Jquery 1.9.1
b) Change to Jquery UI 1.10.1
c) Added 'appendTo' option to the dialog invocation.
a) + b) > c)
I needed to do (c) because I had added (15) jquery dialogs to an existing page that previously had some subform elements disposed as hide/show div elements. I wanted to gain the jquery dialog functionality including modality. Problem was that the subform elements were rewritten by jquery by appending to the document, outside of the elements, thus formfields in the dialogs were no longer included when the form is submitted.
Anyway does anyone have a better solution than the above to this issue ?
版权声明:本文标题:javascript - SCRIPT5007: Unable to get value of the property '0': object is null or undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744968540a2635096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论