how to convert string png to image in javascript -
look @ code!
var imageqrcode; $.ajax({ url: url, data: { c1: ca, c2: cli}, success: function(image) { imageqrcode = image; } });
this html:
<div class="areaqrcode"><img src="javascript:imageqrcode"></div>
my ajax call returns image string this:
"‰png\r\n\u001a\n\u0000\u0000\u0000\rihdr\u0000\u0000\u0000d\u0000\u0000\u0000d\b\u0002\u0000\u0000\u0000ÿ€\u0002\u0003\u0000\u0000\u0000\u0006bkgd\u0000ÿ\u0000ÿ\u0000ÿ ½§“\u0000\u0000\u0001ÞidatxœíÜÁnÄ \feÑrõÿ9Ýzƒä+üj¦ºgÛ4\u0013=y,`\bëyž/õ|ß~€obx€a\u0001†\u0005\u0018\u0016`x€a\u0001?»?¬µÆ?¬Žév÷ßûêõûœØ=ƒ•\u0005\u0018\u0016`xÀ¶gu'óÇnošê;‰ç¬¬,À°\u0000Ã\u0002z=«ê|·;½£3nj÷ z+\u000b0,À°\u0000ܳÒ\u0012ýkŠ•\u0005\u0018\u0016`xÀ+z\u0016]ÛºÅÊ\u0002\f\u000b0,\u0000÷¬©>’îg‰û[y€a\u0001†\u0005´zvâ·9ºžÕ™'&ž³²²\u0000Ã\u0002\f\u000bxo˜97ü‡\f\u000b0,`lÖɾ*ºïajÌeÇqv\u0016`x€a\u0001Ûq\u0016ýÍîä7>Úƒ\u0012ûn;Ïle\u0001†\u0005\u0018\u0016p´?«~Ï\u0013㬓1tbmËÊ\u0002\f\u000b0,`ìwÃn/ûË÷l(ç†Ã\f\u000b0,\u0000¯ÁŸ¼'Ø‘\u0018‹¼çxyy€a\u0001†\u0005Ä÷gm‘w¤×Ô¬,À°\u0000Ã\u0002®ë^û§÷qœ5Ì°\u0000Ã\u0002®ëйæ¤oní«¨¬,À°\u0000Ã\u0002®ë°»>½^Öù\\ç†\u0003\f\u000b0,àÚ;ÒtÏdç\u0013×tv\u0016`x€a\u0001¯8סj¼Ç3uo+\u000b0,À°€kç:p‰µvÚˬ,À°\u0000Ã\u0002®ë0ejݹá0Ã\u0002\f\u000bxŹ\u000eŸÂÊ\u0002\f\u000b0,À°\u0000Ã\u0002\f\u000b0,à\u0017ú\bÐÌ\u001caÐ\u0000\u0000\u0000\u0000iend®b`‚"
but doens't work! i'm doing wrong?
you can use
var imageqrcode; $.ajax({ url: url, data: { c1: ca, c2: cli}, success: function(image) { document .getelementsbyclassname('areaqrcode')[0] .getelementsbytagname('img')[0] .src = 'data:image/png,' + image; } });
note: recommend base64 encode image data before sending it, , use
.src = 'data:image/png;base64,' + image;
Comments
Post a Comment