html - jQuery file reader not working -
jquery code:
var reader = new filereader(); reader.readasdataurl($("#img1").val()); reader.onload = function() { console.log(reader.result); };
html code:
<input type="file" name="img4" id="img1">
i don't know why not working can please me how resolve error?
filereader readasdataurl()
function requires html5 blob or file object, not jquery object. see filereader.readasdataurl() on mdn.
in example can achieve uploading file way:
var file = document.getelementbyid('img1').files[0]; var reader = new filereader(); reader.addeventlistener('load', function() { var res = reader.result; console.log(res); }); reader.readasdataurl(file);
Comments
Post a Comment