views:

785

answers:

3

I retrieve this XML file with

$.ajax({type: "GET", url: "data.xml",dataType: "xml",success: parse });

<Data>
   <user>
      <U_ID>4787<U_ID>
      <U_NAME>Mickey Mouse</N_NAME>
      <U_TYPE>1</U_TYPE>
      <U_PIC>iVBORw0KGgoAAAANSUhEUgAAAHgAAAB0CAYAAABOpv</U_PIC> 
   </user>
</Data>

Where <U_PIC> contains a base64 encoded picture (i have cut the string here for easy demo, it actually is a very long string)

How should I

  • retrieve this?
  • decode base64 (are there built-in functions)?
  • display somewhere in the DOM?
    //example: (<li><img src="'+retrievedPicture+'=></li>)

I am used to operations like these in a standard parser function:

$(xml).find('user').each(function(){  
   var $node = $(this);
   var name = $node.find('U_NAME').text();
   $('div').append(name);    

ps. Tested the actual binary picture with notepad++ and it's without any error a true png picture.

+1  A: 

In modern browsers you can use Data URI, and in IE use server-side script to decode given string, in php it would look like :

<?php
 header('Content-type: image/png');
 echo base64_decode($_GET['b']);
?>
dev-null-dweller
i understand, php is powerfull, but the project is in jquery and almost finished, so if there really isn't a good way to do it with jq then php.I was more thinking something like this (experimenting): var pico = $.base64Decode($(this).find("U_PIC").text()); //if up is OK, then put it inside src attribute inside <img>But...i don't know if it will be that easy?ps. base64Decode(encode) is a plugin i found
pectoralis
...tried it different ways...all i get is a page full of winding-like characters
pectoralis
A: 

Yes, thx a lot, DATA URI did the job

pectoralis
A: 

Hi,

IE has a limit on the image size displayed using DataURI

Does the jQuery method work around this?

Have you tried it?

Test Coder