Reputation: 3130
My code -
$selectFile = $('<input type="file">');
$selectFile.click(function () {
this.value = null;
});
$selectFile.change(function(event){
var reader = new FileReader();
reader.readAsDataURL(event.target.files[0]);
reader.onloadend(function(e){
alert(e.result);
});
});
I am getting object is not a function error at reader.onloadend
line.
Can anyone help please.
Upvotes: 0
Views: 4733
Reputation: 10407
You need to change your onloadend
method to onload
. Also you need to set it to a function, not a parameter. To get the url/data you want use e.target.result
not just e.result
. Finally, I'd place the readAsDataURL
after setting the method to make sure that it fires.
$selectFile.change(function(event){
var reader = new FileReader();
reader.onload = function(e){
alert(e.target.result);
};
reader.readAsDataURL(event.target.files[0]);
});
Upvotes: 1