-1

When create some 64base image and copy src of it like

orig_src.src = image_target.src;

I have next "Resource interpreted as Image but transferred with MIME type text/html:".
So I delete all not important code and create Jsffidle demo So this is simple image chooser and it previews choosen image, and it must alert src of this file, but it is alerting link of page. Why? It is interesting that if who second time image it works fine. How can I fix it and what is the reason of such behavior?

asked Feb 22, 2015 at 20:11

1 Answer 1

1

You are alerting before the reader.onload event is fired, because it takes time to load the image. It is asynchronous, which means that your code just keeps executing until it's loaded. Just move your alert() statement inside reader.onload:

reader.onload = function (event) {
 e.target.parentNode.getElementsByTagName("img")[0].setAttribute('src',event.target.result);
 alert(e.target.parentNode.getElementsByTagName("img")[0].src);
}
answered Feb 22, 2015 at 20:16
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.